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:
Split a String in Java
String Initialization in Java
Spring WebClient and OAuth2 Support
Encode a String to UTF-8 in Java
Java Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph
Java Program to Implement the Binary Counting Method to Generate Subsets of a Set
Arrays.asList vs new ArrayList(Arrays.asList())
A Guide to JPA with Spring
Java Program to Generate Random Numbers Using Probability Distribution Function
Java Program to Represent Linear Equations in Matrix Form
Java Program to Implement Ternary Tree
A Guide to System.exit()
Intro to the Jackson ObjectMapper
Quick Guide to Spring Bean Scopes
Java Program to Implement WeakHashMap API
Apache Tiles Integration with Spring MVC
Guide to the Fork/Join Framework in Java
Configuring a DataSource Programmatically in Spring Boot
The SpringJUnitConfig and SpringJUnitWebConfig Annotations in Spring 5
Java Program to Implement Bubble Sort
Validate email address exists or not by Java Code
Java Program to Implement Max-Flow Min-Cut Theorem
REST Web service: Basic Authentication trong Jersey 2.x
New Stream Collectors in Java 9
Converting a Stack Trace to a String in Java
Using Custom Banners in Spring Boot
Spring Data JPA Delete and Relationships
String Joiner trong Java 8
Getting a File’s Mime Type in Java
Java Program to Implement Rope
Basic Authentication with the RestTemplate
Java Program to Implement Selection Sort