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:
Database Migrations with Flyway
Java Program to Perform Left Rotation on a Binary Search Tree
Spring Boot - Logging
Arrays.asList vs new ArrayList(Arrays.asList())
Java Program to Implement Quick Sort Using Randomization
Java Program to Implement Hash Tables Chaining with Binary Trees
Java Program to Implement the String Search Algorithm for Short Text Sizes
Java Program to Implement Segment Tree
JUnit5 Programmatic Extension Registration with @RegisterExtension
Wrapper Classes in Java
Spring Boot - Database Handling
Java Program to Solve Travelling Salesman Problem for Unweighted Graph
Java Program to Implement Skew Heap
Java – Reader to InputStream
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
Remove HTML tags from a file to extract only the TEXT
Converting a Stack Trace to a String in Java
Java Program to Implement RenderingHints API
Java Program to Create a Random Graph Using Random Edge Generation
Ép kiểu trong Java (Type casting)
Java – Create a File
Java Program to Implement Adjacency List
Collect a Java Stream to an Immutable Collection
Giới thiệu Google Guice – Aspect Oriented Programming (AOP)
Batch Processing with Spring Cloud Data Flow
Spring Boot - Cloud Configuration Server
Spring Boot - Enabling Swagger2
Java Program to Check whether Directed Graph is Connected using BFS
Exploring the Spring Boot TestRestTemplate
Java Program to Perform the Sorting Using Counting Sort
Apache Tiles Integration with Spring MVC
Spring MVC Custom Validation