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 Traveling Salesman Problem using Nearest neighbour Algorithm
Java Program to Implement Disjoint Set Data Structure
Spring Boot Change Context Path
The Basics of Java Security
Guide To CompletableFuture
Converting Iterator to List
Giới thiệu Google Guice – Aspect Oriented Programming (AOP)
How to Convert List to Map in Java
Java Program to Implement JobStateReasons API
Understanding Memory Leaks in Java
File Upload with Spring MVC
Java Program to Describe the Representation of Graph using Adjacency Matrix
Java Program to Implement Borwein Algorithm
Supplier trong Java 8
HTTP Authentification and CGI/Servlet
XML-Based Injection in Spring
An Intro to Spring Cloud Vault
Static Content in Spring WebFlux
Spring Boot - Rest Controller Unit Test
Spring Boot - Interceptor
Injecting Prototype Beans into a Singleton Instance in Spring
Performance Difference Between save() and saveAll() in Spring Data
Convert XML to JSON Using Jackson
Implementing a Binary Tree in Java
Constructor Injection in Spring with Lombok
The Spring @Controller and @RestController Annotations
How to Use if/else Logic in Java 8 Streams
Java Program to Generate a Random UnDirected Graph for a Given Number of Edges
Removing Elements from Java Collections
Call Methods at Runtime Using Java Reflection
ETL with Spring Cloud Data Flow
Spring Boot - Creating Docker Image