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:
A Guide to Spring Cloud Netflix – Hystrix
Java Program to Implement Find all Back Edges in a Graph
Java Program to implement Associate Array
Spring Boot - Tomcat Deployment
Giới thiệu JDBC Connection Pool
Java Program to Implement Fermat Factorization Algorithm
Java Multi-line String
Removing all duplicates from a List in Java
Java Program to Implement the Hill Cypher
Count Occurrences of a Char in a String
Instance Profile Credentials using Spring Cloud
Java Program to Find Transitive Closure of a Graph
Hướng dẫn Java Design Pattern – MVC
Java Program to Perform Searching Using Self-Organizing Lists
Jackson – Decide What Fields Get Serialized/Deserialized
HttpClient with SSL
Setting Up Swagger 2 with a Spring REST API
Java Program to Optimize Wire Length in Electrical Circuit
Debugging Reactive Streams in Java
Java Program to Check if an UnDirected Graph is a Tree or Not Using DFS
How to Define a Spring Boot Filter?
HttpClient 4 – Follow Redirects for POST
@Order in Spring
Exploring the New Spring Cloud Gateway
Java InputStream to String
Notify User of Login From New Device or Location
Spring Boot: Customize Whitelabel Error Page
Prevent Brute Force Authentication Attempts with Spring Security
A Guide to JPA with Spring
Guide to Selenium with JUnit / TestNG
Lớp lồng nhau trong java (Java inner class)
Hướng dẫn Java Design Pattern – Chain of Responsibility