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:
Check If a String Is Numeric in Java
Comparing getPath(), getAbsolutePath(), and getCanonicalPath() in Java
Tránh lỗi NullPointerException trong Java như thế nào?
JUnit5 @RunWith
Stack Memory and Heap Space in Java
Overview of the java.util.concurrent
Cachable Static Assets with Spring MVC
Setting the Java Version in Maven
Java Program to Implement Best-First Search
Java Program to Implement the RSA Algorithm
A Guide to Java 9 Modularity
Java Program to Implement Vector API
Lớp HashMap trong Java
Java Program to Solve Travelling Salesman Problem for Unweighted Graph
Java Program to Generate Randomized Sequence of Given Range of Numbers
Java Program to Implement ArrayDeque API
Java 8 Collectors toMap
Guide to Java Instrumentation
Working with Tree Model Nodes in Jackson
Lớp Properties trong java
Java Program to Find the Longest Subsequence Common to All Sequences in a Set of Sequences
A Guide to EnumMap
Java Program to Implement Singly Linked List
Java Program to Use Dynamic Programming to Solve Approximate String Matching
Spring Cloud AWS – RDS
Java Program to Perform Polygon Containment Test
Giới thiệu Google Guice – Injection, Scope
Guide to WeakHashMap in Java
Java Program to Implement Sparse Array
How to Return 404 with Spring WebFlux
Java Program to Implement Hash Tree
Java Program to Check if a Point d lies Inside or Outside a Circle Defined by Points a, b, c in a Pl...