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:
Java Program to Implement Weight Balanced Tree
Java Program to Implement the Program Used in grep/egrep/fgrep
Java Program to Implement Sorted Doubly Linked List
Java Program to Find Nearest Neighbor Using Linear Search
Split a String in Java
Java Program to Implement Find all Cross Edges in a Graph
Remove HTML tags from a file to extract only the TEXT
Simple Single Sign-On with Spring Security OAuth2
Java Program to Implement a Binary Search Algorithm for a Specific Search Sequence
Implementing a Runnable vs Extending a Thread
Java Program to Implement EnumMap API
Consuming RESTful Web Services
Introduction to the Java NIO2 File API
Java Web Services – Jersey JAX-RS – REST và sử dụng REST API testing tools với Postman
Java Program to Implement Booth Algorithm
Java Program to Compute the Volume of a Tetrahedron Using Determinants
Java Program to Implement Horner Algorithm
Java Program to Implement Binary Search Tree
Java Program to Perform Optimal Paranthesization Using Dynamic Programming
Comparing Arrays in Java
Immutable ArrayList in Java
Java – InputStream to Reader
Java Program to Implement Treap
Spring Security 5 – OAuth2 Login
Debugging Reactive Streams in Java
Jackson – JsonMappingException (No serializer found for class)
Java Program to Describe the Representation of Graph using Adjacency Matrix
Introduction to Spring Data JDBC
Daemon Threads in Java
Java Program to Implement ArrayBlockingQueue API
Thao tác với tập tin và thư mục trong Java
Spring Boot - OAuth2 with JWT