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:
JUnit 5 @Test Annotation
Receive email using IMAP
Java Program to Implement Flood Fill Algorithm
Java Program to Apply DFS to Perform the Topological Sorting of a Directed Acyclic Graph
Java Optional as Return Type
Java Program to Perform Postorder Non-Recursive Traversal of a Given Binary Tree
Guide to Spring Cloud Kubernetes
How to use the Spring FactoryBean?
Java Program to Find Nearest Neighbor for Static Data Set
Guide to the Java ArrayList
Spring Boot Integration Testing with Embedded MongoDB
Call Methods at Runtime Using Java Reflection
Upload and Display Excel Files with Spring MVC
Java Program to Solve a Matching Problem for a Given Specific Case
Java Program to Implement Quick Hull Algorithm to Find Convex Hull
Java Program to Implement Caesar Cypher
Jackson Ignore Properties on Marshalling
Java Program to Implement Repeated Squaring Algorithm
Class Loaders in Java
Java equals() and hashCode() Contracts
Derived Query Methods in Spring Data JPA Repositories
Intro to Spring Boot Starters
Functional Interfaces in Java 8
Spring MVC and the @ModelAttribute Annotation
Giới thiệu thư viện Apache Commons Chain
Java Program to Implement Cartesian Tree
Java Program to Implement EnumMap API
Java Program to Delete a Particular Node in a Tree Without Using Recursion
Java Program to Implement Binary Search Tree
Marker Interface trong Java
Tổng quan về ngôn ngữ lập trình java
ETags for REST with Spring