This is a java program to perform search using string library.
Here is the source code of the Java Program to Perform String Matching Using String Library. 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; public class StringSearchUsingStrLib { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out.println("Enter the main string: "); String text = sc.nextLine(); System.out.println("Enter the pattern string: "); String pattern = sc.nextLine(); for (int i = 0; i <= (text.length() - pattern.length()); i++) { if (text.substring(i, (i + pattern.length())).equalsIgnoreCase( pattern)) { System.out.println(pattern + " is substring of main string, match found at: " + ++i); } } sc.close(); } }
Output:
$ javac StringSearchUsingStrLib.java $ java StringSearchUsingStrLib Enter the main string: Java Program to Perform String Matching Using String Library Enter the pattern string: String String is substring of main string, match found at: 25 String is substring of main string, match found at: 47
Related posts:
Spring Data Java 8 Support
Java Program to Implement the Vigenere Cypher
Setting Up Swagger 2 with a Spring REST API
Java Program to Implement Hash Tables with Double Hashing
Giới thiệu java.io.tmpdir
Java Program to Perform Optimal Paranthesization Using Dynamic Programming
Database Migrations with Flyway
Guide to the Java ArrayList
Java Program to Implement Splay Tree
A Quick Guide to Spring Cloud Consul
Java Program to Implement Patricia Trie
What is a POJO Class?
Java – Try with Resources
Java Program to Perform Searching in a 2-Dimension K-D Tree
A Guide to Iterator in Java
Multi Dimensional ArrayList in Java
Java Program to Implement ConcurrentHashMap API
Java Program to Represent Graph Using Incidence Matrix
Guide to Guava Table
Java Program to Implement Interpolation Search Algorithm
Anonymous Classes in Java
Java Program to Find the Shortest Path Between Two Vertices Using Dijkstra’s Algorithm
Java Program to Perform integer Partition for a Specific Case
Java Program to Implement Ternary Tree
Java Program to Check Whether an Undirected Graph Contains a Eulerian Cycle
Reading an HTTP Response Body as a String in Java
Java Program to Solve Knapsack Problem Using Dynamic Programming
An Intro to Spring Cloud Vault
Lớp Arrarys trong Java (Arrays Utility Class)
Java Program to Perform Addition Operation Using Bitwise Operators
Disable Spring Data Auto Configuration
Filtering a Stream of Optionals in Java