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 HashMap API
Custom Cascading in Spring Data MongoDB
Hướng dẫn Java Design Pattern – Abstract Factory
A Guide to the Java ExecutorService
Java Program to Check the Connectivity of Graph Using DFS
Java Program to Implement Max-Flow Min-Cut Theorem
Check If Two Lists are Equal in Java
Service Registration with Eureka
Comparing Objects in Java
Spring’s RequestBody and ResponseBody Annotations
Java Program to Implement Branch and Bound Method to Perform a Combinatorial Search
Call Methods at Runtime Using Java Reflection
Rest Web service: Filter và Interceptor với Jersey 2.x (P1)
Java Program to Implement Ternary Heap
Fixing 401s with CORS Preflights and Spring Security
Split a String in Java
Guide to CountDownLatch in Java
Command-Line Arguments in Java
Spring Data JPA @Query
Java Program to Implement Control Table
Apache Commons Collections Bag
How to Remove the Last Character of a String?
Java Program to do a Breadth First Search/Traversal on a graph non-recursively
Lập trình đa luồng với Callable và Future trong Java
Guide to the Synchronized Keyword in Java
Spring REST with a Zuul Proxy
Hướng dẫn sử dụng Lớp FilePermission trong java
Java Program to Implement RoleUnresolvedList API
wait() and notify() Methods in Java
Lớp TreeMap trong Java
Spring Data MongoDB Transactions
Java Program to Find Median of Elements where Elements are Stored in 2 Different Arrays