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 Program to Check Whether a Weak Link i.e. Articulation Vertex Exists in a Graph
Spring Boot - Rest Controller Unit Test
Java Program to Solve a Matching Problem for a Given Specific Case
Giới thiệu luồng vào ra (I/O) trong Java
Introduction to Spring Cloud CLI
Service Registration with Eureka
Implementing a Binary Tree in Java
A Guide to WatchService in Java NIO2
Java Program to Implement Hash Tables Chaining with Doubly Linked Lists
Quick Guide to Spring MVC with Velocity
How to Read a File in Java
Java Program to Solve TSP Using Minimum Spanning Trees
Java Program to Implement Max-Flow Min-Cut Theorem
Java Program to Implement ArrayList API
Command-Line Arguments in Java
Guide to CopyOnWriteArrayList
XML-Based Injection in Spring
Spring Boot - Servlet Filter
How to Change the Default Port in Spring Boot
Enum trong java
REST Pagination in Spring
Java Program to Implement the Checksum Method for Small String Messages and Detect
Java Program to Implement Gale Shapley Algorithm
Spring NoSuchBeanDefinitionException
Java Program to Compute Cross Product of Two Vectors
Vấn đề Nhà sản xuất (Producer) – Người tiêu dùng (Consumer) và đồng bộ hóa các luồng trong Java
Java Program to Find the Vertex Connectivity of a Graph
Inject Parameters into JUnit Jupiter Unit Tests
Create Java Applet to Simulate Any Sorting Technique
Getting Started with Custom Deserialization in Jackson
The StackOverflowError in Java
Spring Boot - Runners