Add method .equalsOr() to String class

  • A+
Category:Languages

I'm just starting with Java.

I wonder if there's a way to add a method so that any String can call that method, similar to how we have now string1.equals(string2) that you could use string1.equalsOr(string2, string3, string4, string5).

I know I can make my own static method, but wonder if I could make it available to any string.

 


If you want to check equality of your string1 to a set of strings string2, string3, string4, string5. It's better to use any collection (i.e. Set or List). For example, if you use

 Arrays.asList(string2, string3, string4, string5).contains(string1) 

it will give you the espected result.

Comment

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: