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:
Tạo ứng dụng Java RESTful Client với thư viện OkHttp
Java Program to Find the Edge Connectivity of a Graph
Java Stream Filter with Lambda Expression
Rate Limiting in Spring Cloud Netflix Zuul
An Intro to Spring Cloud Zookeeper
Java Program to Implement LinkedBlockingDeque API
Testing an OAuth Secured API with Spring MVC
Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java
Migrating from JUnit 4 to JUnit 5
Iterable to Stream in Java
Java Program to Implement Radix Sort
Java Program to Find the GCD and LCM of two Numbers
How to Read a File in Java
Shuffling Collections In Java
Java Program to Perform Preorder Recursive Traversal of a Given Binary Tree
Lớp LinkedHashMap trong Java
Hướng dẫn Java Design Pattern – Mediator
Collect a Java Stream to an Immutable Collection
Transactions with Spring and JPA
Java Program to Implement Floyd-Warshall Algorithm
Java Program to Perform Arithmetic Operations on Numbers of Size
Case-Insensitive String Matching in Java
Spring Security Form Login
Apache Commons Collections OrderedMap
Simplify the DAO with Spring and Java Generics
Convert Hex to ASCII in Java
Spring Boot - Google Cloud Platform
Vấn đề Nhà sản xuất (Producer) – Người tiêu dùng (Consumer) và đồng bộ hóa các luồng trong Java
Java Program to Implement Branch and Bound Method to Perform a Combinatorial Search
Spring 5 WebClient
Java Program to Implement Fermat Factorization Algorithm
Join and Split Arrays and Collections in Java