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:
The Modulo Operator in Java
Spring Boot - Quick Start
Guide to Character Encoding
Java Program to Implement Treap
Java Program to Generate a Random UnDirected Graph for a Given Number of Edges
ETL with Spring Cloud Data Flow
Java Program to Implement Control Table
Configuring a DataSource Programmatically in Spring Boot
Jackson – Bidirectional Relationships
Class Loaders in Java
Hướng dẫn Java Design Pattern – Prototype
Spring Boot - Twilio
Java Program to Find ith Largest Number from a Given List Using Order-Statistic Algorithm
New Stream Collectors in Java 9
Collection trong java
Converting a List to String in Java
Jackson JSON Views
Injecting Prototype Beans into a Singleton Instance in Spring
Java Program to Check Whether Graph is DAG
Multi Dimensional ArrayList in Java
Java Program to Generate Random Numbers Using Probability Distribution Function
Java Program to Find Location of a Point Placed in Three Dimensions Using K-D Trees
Object Type Casting in Java
Java Program to Find the Shortest Path from Source Vertex to All Other Vertices in Linear Time
Handle EML file with JavaMail
HttpClient Connection Management
Java Program to Implement Disjoint Sets
Java Program to Implement Counting Sort
What is Thread-Safety and How to Achieve it?
Spring Security OAuth Login with WebFlux
Java Program to Describe the Representation of Graph using Adjacency Matrix
Using a Spring Cloud App Starter