This is a java program to perform search using Vectors.
Here is the source code of the Java Program to Implement String Matching Using Vectors. The Java program is successfully compiled and run on a Windows system. The program output is also shown below.
package com.maixuanviet.setandstring; import java.util.Scanner; import java.util.Vector; public class StringSearchUsingVectors { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the main string: "); Vector<String> text = new Vector<String>(); text.add(sc.nextLine()); System.out.println("Enter the pattern string: "); Vector<String> pattern = new Vector<String>(); pattern.add(sc.nextLine()); for (int i = 0; i <= text.elementAt(0).length() - pattern.elementAt(0).length(); i++) { if (text.elementAt(0) .substring(i, i + pattern.elementAt(0).length()) .equalsIgnoreCase(pattern.elementAt(0))) { System.out.println(pattern.elementAt(0) + " is substring of main string, match found at: " + ++i); } } sc.close(); } }
Output:
$ javac StringSearchUsingVectors.java $ java StringSearchUsingVectors Enter the main string: Java Program to Implement String Matching Using Vectors Enter the pattern string: Vectors Vectors is substring of main string, match found at: 49
Related posts:
Guava CharMatcher
Java Program to Implement Hash Tables chaining with Singly Linked Lists
Guava – Join and Split Collections
Custom HTTP Header with the HttpClient
Hướng dẫn Java Design Pattern – Visitor
Introduction to the Functional Web Framework in Spring 5
Sử dụng CountDownLatch trong Java
Java Program to Implement a Binary Search Algorithm for a Specific Search Sequence
JPA/Hibernate Persistence Context
Spring Boot - Interceptor
Java Program to Implement Sorted Doubly Linked List
Check if a String is a Palindrome in Java
Java Program to Find SSSP (Single Source Shortest Path) in DAG (Directed Acyclic Graphs)
Java – Write an InputStream to a File
Count Occurrences of a Char in a String
Introduction to Project Reactor Bus
Spring WebClient vs. RestTemplate
Concurrent Test Execution in Spring 5
Java Program to Implement Stack using Two Queues
Posting with HttpClient
Java Program to Find the Peak Element of an Array O(n) time (Naive Method)
Adding a Newline Character to a String in Java
Spring MVC Setup with Kotlin
Java Program to Implement Direct Addressing Tables
Spring Cloud Bus
Hướng dẫn Java Design Pattern – Factory Method
Lớp Collections trong Java (Collections Utility Class)
Comparing Two HashMaps in Java
Arrays.asList vs new ArrayList(Arrays.asList())
Dynamic Proxies in Java
Java Program to Implement Disjoint Set Data Structure
Java Program to Implement Quick Sort with Given Complexity Constraint