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:
Upload and Display Excel Files with Spring MVC
Shuffling Collections In Java
Java Program to Implement Traveling Salesman Problem using Nearest neighbour Algorithm
Java Program to Implement K Way Merge Algorithm
Cài đặt và sử dụng Swagger UI
Logout in an OAuth Secured Application
Jackson Date
Java Program to Optimize Wire Length in Electrical Circuit
Xử lý ngoại lệ trong Java (Exception Handling)
Java 8 Streams peek() API
Java – Reader to Byte Array
Java Program to Describe the Representation of Graph using Incidence Matrix
Giới thiệu về Stream API trong Java 8
Java List UnsupportedOperationException
Java Program to Create a Minimal Set of All Edges Whose Addition will Convert it to a Strongly Conne...
Biểu thức Lambda trong Java 8 – Lambda Expressions
Refactoring Design Pattern với tính năng mới trong Java 8
Java Program to Generate Date Between Given Range
Java Program to Find the Edge Connectivity of a Graph
Lớp lồng nhau trong java (Java inner class)
Using Custom Banners in Spring Boot
Assertions in JUnit 4 and JUnit 5
Java Perform to a 2D FFT Inplace Given a Complex 2D Array
Spring Boot - CORS Support
Java Program to Implement Graham Scan Algorithm to Find the Convex Hull
Spring Data – CrudRepository save() Method
JPA/Hibernate Persistence Context
How to Kill a Java Thread
Java Program to Construct a Random Graph by the Method of Random Edge Selection
The Dining Philosophers Problem in Java
How to Return 404 with Spring WebFlux
An Intro to Spring Cloud Vault