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 – String to Reader
Refactoring Design Pattern với tính năng mới trong Java 8
Tìm hiểu về Web Service
Java Program to implement Dynamic Array
Java Program to Compute the Area of a Triangle Using Determinants
Comparing Long Values in Java
How to use the Spring FactoryBean?
Custom Thread Pools In Java 8 Parallel Streams
Serverless Functions with Spring Cloud Function
Spring Cloud – Securing Services
Java Program to Implement LinkedHashSet API
Spring REST with a Zuul Proxy
Guide to ThreadLocalRandom in Java
Generate Spring Boot REST Client with Swagger
Java Program to Check whether Graph is a Bipartite using BFS
Java Program to implement Bi Directional Map
Spring Boot - CORS Support
Java Program to Represent Graph Using Adjacency Matrix
Convert String to int or Integer in Java
Java Program to Implement ScapeGoat Tree
Java Program to Implement Miller Rabin Primality Test Algorithm
Hướng dẫn Java Design Pattern – Memento
Java Program to Implement Max Heap
Java Stream Filter with Lambda Expression
Java Program to Implement DelayQueue API
Converting a List to String in Java
Java Program to Find the GCD and LCM of two Numbers
Java Program to Implement LinkedBlockingDeque API
Java InputStream to Byte Array and ByteBuffer
Java Program to Perform Quick Sort on Large Number of Elements
Java Program to Check whether Graph is Biconnected
Java Program to Implement Find all Back Edges in a Graph