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:
Intro to Spring Boot Starters
Giới thiệu Google Guice – Injection, Scope
Java Byte Array to InputStream
Collect a Java Stream to an Immutable Collection
Java Program to Implement Sorted Circular Doubly Linked List
Hướng dẫn Java Design Pattern – Visitor
Collection trong java
Guide to @ConfigurationProperties in Spring Boot
Java Program to Implement D-ary-Heap
Object Type Casting in Java
Guide to Java OutputStream
Java Program to Implement RoleList API
Java Program to Implement Sorted Singly Linked List
Java Program to Compute Discrete Fourier Transform Using the Fast Fourier Transform Approach
Iterating over Enum Values in Java
How to Round a Number to N Decimal Places in Java
Guide to Spring 5 WebFlux
Working with Network Interfaces in Java
DistinctBy in the Java Stream API
Java Program to Implement the Vigenere Cypher
XML-Based Injection in Spring
Spring RestTemplate Request/Response Logging
A Guide to Iterator in Java
Java Program to Check whether Directed Graph is Connected using BFS
Guide to Guava Table
Convert XML to JSON Using Jackson
Transactions with Spring and JPA
Validations for Enum Types
Registration – Password Strength and Rules
Hướng dẫn Java Design Pattern – State
Jackson Unmarshalling JSON with Unknown Properties
JUnit 5 @Test Annotation