How do I check if part if one string is equal to another? For example if I have one string with the value of "hello" and a string with the value of "he", how can I compare them to check that "hello" contains "he".
If that was not explained very well tell me and I will try to clear it up
Using Double Equal To Operator While equals() is a method, == is an operator. == operator is used for reference comparison, while on the other hand, equals() method is used for content comparison.
Java String equals() Method The equals() method compares two strings, and returns true if the strings are equal, and false if not. Tip: Use the compareTo() method to compare two strings lexicographically.
This example demonstrate about How to use compare string in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
You should not use == (equality operator) to compare these strings because they compare the reference of the string, i.e. whether they are the same object or not. On the other hand, equals() method compares whether the value of the strings is equal, and not the object itself.
"Hello".toLowerCase().contains("He".toLowercase());
same like java by using String class contains() method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With