StringUtils equalsAny method

By | May 1, 2020

StringUtils equalsAny method is used to compare a string with n number of strings at a time. equalsAny method is present in the lang3 package i.e import org.apache.commons.lang3.StringUtils. If you use import org.apache.commons.lang.StringUtils in your code, equalsAny method won’t be available.

Compares given string to a CharSequences of searchStrings and returns true if the string is equal to any of the searchStrings otherwise returns false.

  • equalsAny
  • equalsAnyIgnoreCase

Both the methods are case sensitive.




Below are the methods provided in StringUtils class and these are all null safe.

Equals/Compare: It compares whether two given strings are equal or not.
EqualsAny: Compares if the first string is equal to the given searchStrings.
IsEmpty/IsBlank: checks if a String contains text
Trim/Strip: removes leading and trailing whitespace from string.
startsWith: check if a String starts with a prefix / specified characters
endsWith: check if a String ends with a suffix / specified characters.
UpperCase/LowerCase/SwapCase/Capitalize/Uncapitalize: Used to change the case of a String
IndexOf/LastIndexOf/Contains: checks the index of string
IndexOfAny/LastIndexOfAny/IndexOfAnyBut/LastIndexOfAnyBut: Checks the index of given Strings
ContainsOnly/ContainsNone/ContainsAny: does String contains only/none/any of these characters
IsAlpha/IsNumeric/IsWhitespace/IsAsciiPrintable: checks the characters in a String

Reverse/ReverseDelimited: It reverses a String
Substring/Left/Right/Mid: It extracts substrings
SubstringBefore/SubstringAfter/SubstringBetween: substring extraction relative to other strings
Split/Join: Splits a String into an array of substrings and vice versa
Remove/Delete: It removes part of a String
Replace/Overlay: Searches a String and replaces one String with another
LeftPad/RightPad/Center/Repeat: It adds padding to a String


Using stringutils equalsAny method we can compare multiple strings against a single string at a time. This method is present in the package org.apache.commons.lang3.StringUtils. So you should import lang3 package to make use of stringutils equalsany method.

Recommended Posts:

All StringUtils methods with examples

Get last 4 chars from String

Convert String to String array

SQL quick reference for interview preparation

Source: Apache

Tags: stringutils equalsany method

Leave a Reply

Your email address will not be published. Required fields are marked *