As its name implies startsWith
says whether the String
begins with certain text. To know contain the text anywhere and not specifically at the beginning use contains
:
String query = "Policia Militar";
query.contains("Policia"); // true
query.contains("Militar"); // true
However note that the search has to be accurate as far as uppercase and minuscule are concerned, so if you search for militar
will not give true:
query.contains("militar"); // false
If this is a problem, you can change the logic to turn both to uppercase or minuscule before the comparison, which you already solve. This change can be made both with toLowerCase
as with toUpperCase
:
String pesquisa = "militar";
query.toLowerCase().contains(pesquisa.toLowerCase()); //true
See these examples in Ideone
Enter your code so we can help
– Costamilam
Be clearer on your question, put the code or some example.
– Mike Otharan