Check String Contains Another String | Code Factory

package com.codeFactory;import org.apache.commons.lang3.StringUtils;/**
* @author code.factory
*
*/
public class StringContainsString {
public static void main(String... args) {
String str = "Love is a friendship set to music";
System.out.println("String to search: " + str);System.out.println("\nUsing String.contains():");
System.out.println("str.contains(\"love\"): " + str.contains("love"));
System.out.println("str.contains(\"Love\"): " + str.contains("Love"));
System.out.println("\nUsing String.indexOf() processing:");
System.out.println("(str.indexOf(\"love\") > -1 ? true : false): " + (str.indexOf("love") > -1 ? true : false));
System.out.println("(str.indexOf(\"Love\") > -1 ? true : false): " + (str.indexOf("Love") > -1 ? true : false));
System.out.println("\nUsing StringUtils.contains():");
System.out.println("StringUtils.contains(str, \"love\"): " + StringUtils.contains(str, "love"));
System.out.println("StringUtils.contains(str, \"Love\"): " + StringUtils.contains(str, "Love"));
}
}
String to search: Love is a friendship set to musicUsing String.contains():
str.contains("love"): false
str.contains("Love"): true
Using String.indexOf() processing:
(str.indexOf("love") > -1 ? true : false): false
(str.indexOf("Love") > -1 ? true : false): true
Using StringUtils.contains():
StringUtils.contains(str, "love"): false
StringUtils.contains(str, "Love"): true

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

College360 Architecture on AWS

What Agile Development Tools Can Amp Up Your Project?

Weekly Price Update #4

Remote Work: Blowing Off Steam

A Non-Coders Guide to Hackathons

How to Install a Single Master Kubernetes (k8s) Cluster

Serverless CI/CD Using Jenkins X and Spotinst’s Ocean

All the single(ton) ladies 🎵

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

Chapter 6 — Using the Java Library

Inversion of Control (IOC) & Dependency Injection

SOLID Principles

Builder Design Pattern