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:
Java 14 Record Keyword
Autoboxing và Unboxing trong Java
A Guide to the ViewResolver in Spring MVC
Java Program to find the maximum subarray sum using Binary Search approach
Spring MVC Content Negotiation
Filtering and Transforming Collections in Guava
Spring Boot - Hystrix
Vòng lặp for, while, do-while trong Java
Get and Post Lists of Objects with RestTemplate
Jackson JSON Views
LinkedHashSet trong java
Getting Started with Custom Deserialization in Jackson
Deploy a Spring Boot App to Azure
Collect a Java Stream to an Immutable Collection
Java Program to Perform the Unique Factorization of a Given Number
Hướng dẫn sử dụng biểu thức chính quy (Regular Expression) trong Java
Java Program to Implement Sparse Matrix
Hướng dẫn Java Design Pattern – Factory Method
Java Program to Perform Arithmetic Operations on Numbers of Size
Refactoring Design Pattern với tính năng mới trong Java 8
Java Program to Implement Threaded Binary Tree
Java Program to Implement Aho-Corasick Algorithm for String Matching
Spring Boot - Web Socket
Java Program to Sort an Array of 10 Elements Using Heap Sort Algorithm
Java Program to Implement Skip List
Jackson Unmarshalling JSON with Unknown Properties
Java Program to Implement Segment Tree
Spring Cloud – Securing Services
Java Program to Find a Good Feedback Edge Set in a Graph
New Features in Java 9
Java Program to Find the GCD and LCM of two Numbers
Hướng dẫn Java Design Pattern – Observer