Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if part of a string equals another string in android

Tags:

java

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

like image 437
jcw Avatar asked Sep 06 '12 19:09

jcw


People also ask

How can I compare two strings in Android?

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.

How do you check if a string is equal to another string?

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.

How do I check if a string is equal in Android?

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.

Can we use == for String comparison?

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.


1 Answers

"Hello".toLowerCase().contains("He".toLowercase()); same like java by using String class contains() method.

like image 78
kosa Avatar answered Oct 24 '22 19:10

kosa