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:
HashMap trong Java hoạt động như thế nào?
Java Program to Implement Wagner and Fisher Algorithm for online String Matching
Join and Split Arrays and Collections in Java
Compare Two JSON Objects with Jackson
Convert XML to JSON Using Jackson
Function trong Java 8
More Jackson Annotations
Java Program to Compute Cross Product of Two Vectors
Java Program to Find All Pairs Shortest Path
Java Program to Perform Uniform Binary Search
Java Program to Implement ConcurrentSkipListMap API
Java Program to Implement Rolling Hash
Working With Maps Using Streams
Java Program to Implement Bresenham Line Algorithm
Introduction to Spring Data REST
Spring’s RequestBody and ResponseBody Annotations
Spring Boot - Exception Handling
Spring Boot - Batch Service
Java Program to Implement Regular Falsi Algorithm
The DAO with Spring and Hibernate
Java Program to Implement the Bin Packing Algorithm
Introduction to PCollections
Java Program to Implement Floyd-Warshall Algorithm
An Intro to Spring Cloud Security
Phân biệt JVM, JRE, JDK
Consuming RESTful Web Services
Jackson – Change Name of Field
Java Program to Implement Heap’s Algorithm for Permutation of N Numbers
Convert Character Array to String in Java
Spring Boot - Google OAuth2 Sign-In
Guide to @ConfigurationProperties in Spring Boot
Java Program to Compute Discrete Fourier Transform Using the Fast Fourier Transform Approach