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:
Notify User of Login From New Device or Location
Java Program to Perform the Shaker Sort
Java Program to Implement the Hill Cypher
Spring Data MongoDB Transactions
Removing Elements from Java Collections
Java Program to Represent Graph Using Incidence Matrix
Spring WebClient and OAuth2 Support
Java Program to Implement Self organizing List
REST Web service: Upload và Download file với Jersey 2.x
Java Program to Perform Matrix Multiplication
A Guide to Java HashMap
Spring Security OAuth Login with WebFlux
Java – Reader to Byte Array
Hướng dẫn Java Design Pattern – Factory Method
Java Program to Check if a Directed Graph is a Tree or Not Using DFS
Hướng dẫn Java Design Pattern – Decorator
Guide to Spring @Autowired
Java – Write a Reader to File
Mix plain text and HTML content in a mail
Check if a String is a Palindrome in Java
Guide to DelayQueue
New Features in Java 9
Guide to the Volatile Keyword in Java
Number Formatting in Java
How to Return 404 with Spring WebFlux
Java Program to Implement Solovay Strassen Primality Test Algorithm
Spring Security 5 – OAuth2 Login
Java 9 Stream API Improvements
Jackson Exceptions – Problems and Solutions
Guava – Join and Split Collections
Java Program to Implement Binomial Heap
Custom HTTP Header with the HttpClient