Java Program to Implement String Matching Using Vectors

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 Park-Miller Random Number Generation Algorithm
Servlet 3 Async Support with Spring MVC and Spring Security
Java Program to Perform Postorder Non-Recursive Traversal of a Given Binary Tree
Java Program to Implement Multi-Threaded Version of Binary Search Tree
String Operations with Java Streams
Java Program to Implement Patricia Trie
Spring Boot - Twilio
Spring REST API with Protocol Buffers
Java Program to Generate Random Hexadecimal Byte
Java Program to Implement HashTable API
A Guide to Java HashMap
Java Program to Implement Solovay Strassen Primality Test Algorithm
Spring Security Registration – Resend Verification Email
Derived Query Methods in Spring Data JPA Repositories
Java Program to Generate Random Numbers Using Probability Distribution Function
Giới thiệu SOAP UI và thực hiện test Web Service
Spring’s RequestBody and ResponseBody Annotations
A Guide to TreeMap in Java
Java Program to Perform Right Rotation on a Binary Search Tree
Prevent Brute Force Authentication Attempts with Spring Security
Validations for Enum Types
Java Program to Check if a Point d lies Inside or Outside a Circle Defined by Points a, b, c in a Pl...
Allow user:password in URL
Java Program to Solve a Matching Problem for a Given Specific Case
Show Hibernate/JPA SQL Statements from Spring Boot
Java Program to Describe the Representation of Graph using Adjacency Matrix
Java Program to Use Dynamic Programming to Solve Approximate String Matching
Java Program to Solve any Linear Equation in One Variable
Custom Thread Pools In Java 8 Parallel Streams
Read an Outlook MSG file
Một số tính năng mới về xử lý ngoại lệ trong Java 7
Inheritance with Jackson