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:
Getting Started with Forms in Spring MVC
Java Program to Generate Date Between Given Range
The Order of Tests in JUnit
Implementing a Binary Tree in Java
Java Program to Implement Hash Tables with Linear Probing
HttpClient 4 – Send Custom Cookie
Getting Started with GraphQL and Spring Boot
ETL with Spring Cloud Data Flow
JUnit5 @RunWith
Test a REST API with Java
Lớp Collections trong Java (Collections Utility Class)
Java Program to Perform Naive String Matching
A Guide to Spring Boot Admin
Java NIO2 Path API
Tìm hiểu cơ chế Lazy Evaluation của Stream trong Java 8
Java Program to Solve Tower of Hanoi Problem using Stacks
Java Program to Implement Iterative Deepening
Spring Boot - Cloud Configuration Client
Guide to the Java TransferQueue
Guide to UUID in Java
Java Program to Check if a Matrix is Invertible
ExecutorService – Waiting for Threads to Finish
Giới thiệu Design Patterns
An Example of Load Balancing with Zuul and Eureka
Quick Guide on Loading Initial Data with Spring Boot
Custom HTTP Header with the HttpClient
Java – Reader to InputStream
Hướng dẫn sử dụng Java Annotation
Introduction to Spring Method Security
How to Return 404 with Spring WebFlux
Java Program to Implement Best-First Search
Hướng dẫn Java Design Pattern – Decorator