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 Implement VList
Java Byte Array to InputStream
Quick Guide to Spring Controllers
Java InputStream to Byte Array and ByteBuffer
Java String Conversions
Getting Started with Forms in Spring MVC
How to Count Duplicate Elements in Arraylist
Spring Security 5 – OAuth2 Login
Java Program to Find Second Smallest of n Elements with Given Complexity Constraint
wait() and notify() Methods in Java
Java Program to Find Minimum Number of Edges to Cut to make the Graph Disconnected
Java Program to Generate All Pairs of Subsets Whose Union Make the Set
Spring WebClient and OAuth2 Support
Java 8 StringJoiner
Java Program to implement Bi Directional Map
SOAP Web service: Upload và Download file sử dụng MTOM trong JAX-WS
Ép kiểu trong Java (Type casting)
A Custom Media Type for a Spring REST API
The Registration Process With Spring Security
Retrieve User Information in Spring Security
Tạo số và chuỗi ngẫu nhiên trong Java
Java – Try with Resources
Prevent Brute Force Authentication Attempts with Spring Security
Sắp xếp trong Java 8
How to Iterate Over a Stream With Indices
Java Program to Implement the Edmond’s Algorithm for Maximum Cardinality Matching
Spring Boot - Runners
Java Program to Generate All Subsets of a Given Set in the Gray Code Order
StringBuilder vs StringBuffer in Java
Tiêu chuẩn coding trong Java (Coding Standards)
Java Program to Solve the 0-1 Knapsack Problem
Java Program to Implement RenderingHints API