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 14 Record Keyword
Period and Duration in Java
Using a List of Values in a JdbcTemplate IN Clause
Updating your Password
Java Program to do a Depth First Search/Traversal on a graph non-recursively
XML-Based Injection in Spring
Java Program to Generate All Subsets of a Given Set in the Lexico Graphic Order
Service Registration with Eureka
Java Program to Implement Hopcroft Algorithm
Java Program to Implement Levenshtein Distance Computing Algorithm
Java Program to Perform Polygon Containment Test
Java Program to Implement Ternary Search Algorithm
Java Program to Test Using DFS Whether a Directed Graph is Weakly Connected or Not
Spring Security – security none, filters none, access permitAll
Giới thiệu luồng vào ra (I/O) trong Java
Hướng dẫn Java Design Pattern – Object Pool
Java Program to Implement Find all Back Edges in a Graph
Java Program to Implement Vector API
Create a Custom Auto-Configuration with Spring Boot
Phân biệt JVM, JRE, JDK
Spring MVC + Thymeleaf 3.0: New Features
The Registration Process With Spring Security
Mệnh đề Switch-case trong java
Generating Random Numbers in a Range in Java
Java Program to Implement EnumMap API
Introduction to Spring Cloud Stream
How to Set TLS Version in Apache HttpClient
Remove All Occurrences of a Specific Value from a List
A Guide to LinkedHashMap in Java
Receive email by java client
Giới thiệu Google Guice – Binding
Jackson Exceptions – Problems and Solutions