would you please let me know if there is a way(java) to check is a string is exist in a long string? example: check if the word hello is exist in this string "abcdffgfghdshghelloasdf" in this case true sould be returned .
Best Regards, Maya
would you please let me know if there is a way(java) to check is a string is exist in a long string? example: check if the word hello is exist in this string "abcdffgfghdshghelloasdf" in this case true sould be returned .
Best Regards, Maya
 
    
    This can be done simply by using contains method
String orig="abcdffgfghdshghelloasdf";
if (orig.contains("hello"))
    return true;
else
    return false;
 
    
     
    
    In Java you can do that in many ways, for example by using methods from String class:
Contains method - takes CharSequence as parameter:
boolean checkContains(){
    String orig="abcdffgfghdshghelloasdf";
    return orig.contains("hello");
}
Matches method - takes regex as parameter:
boolean checkMatches(){
    String orig="abcdffgfghdshghelloasdf";
    return orig.matches(".*hello.*");
}
Both of them are really fast, so there is no big difference which of them you will use.
