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:
Immutable Objects in Java
Java Program to Compare Binary and Sequential Search
Apache Commons Collections SetUtils
A Quick Guide to Using Keycloak with Spring Boot
Java Program to Implement Graph Structured Stack
Java Program to Find the Minimum value of Binary Search Tree
A Guide to TreeSet in Java
Spring Data – CrudRepository save() Method
Convert XML to JSON Using Jackson
Jackson Exceptions – Problems and Solutions
How to Find an Element in a List with Java
Guide to the Java TransferQueue
Spring Security Remember Me
Tạo ứng dụng Java RESTful Client với thư viện OkHttp
Java Program to Implement JobStateReasons API
Toán tử trong java
Dynamic Proxies in Java
wait() and notify() Methods in Java
New Features in Java 15
Java Program to Perform Complex Number Multiplication
Guide to Java OutputStream
The Dining Philosophers Problem in Java
Circular Dependencies in Spring
Java Program to Perform Addition Operation Using Bitwise Operators
Java Program to Check Whether an Undirected Graph Contains a Eulerian Cycle
Overflow and Underflow in Java
Java Program to Find Strongly Connected Components in Graphs
ClassNotFoundException vs NoClassDefFoundError
Java Program to Implement Quick sort
Weak References in Java
Java Program to Implement Extended Euclid Algorithm
Mảng (Array) trong Java