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ính đóng gói (Encapsulation) trong java
New Stream Collectors in Java 9
Java Program to Find the Edge Connectivity of a Graph
Extra Login Fields with Spring Security
The Thread.join() Method in Java
Creating Docker Images with Spring Boot
Java Program to Implement Lloyd’s Algorithm
Java Program to Check if a Given Set of Three Points Lie on a Single Line or Not
Converting Java Date to OffsetDateTime
Java Program to Implement Hash Trie
Java Program to Find Number of Spanning Trees in a Complete Bipartite Graph
Tạo ứng dụng Java RESTful Client với thư viện Retrofit
Overview of the java.util.concurrent
Hướng dẫn sử dụng Lớp FilePermission trong java
Spring Boot Annotations
Send an email using the SMTP protocol
Multi Dimensional ArrayList in Java
How to Get a Name of a Method Being Executed?
Java Program to Implement Sorted Singly Linked List
Guide to System.gc()
Spring MVC Setup with Kotlin
Java Program to Implement the Monoalphabetic Cypher
Map Interface trong java
Java Program to Implement Expression Tree
Java String Conversions
Java Program to Implement Patricia Trie
Java toString() Method
Jackson – JsonMappingException (No serializer found for class)
Converting a Stack Trace to a String in Java
Getting a File’s Mime Type in Java
Java Program to Find the Shortest Path from Source Vertex to All Other Vertices in Linear Time
Daemon Threads in Java