I have a string, say a="1.1" and an arraylist, say list, which has the strings: "1.1.1.1", "1.1.2.4","1.2,1.3","1.5.1.1"
Now, I want to get the strings from this arraylist, which contains the string a="1.1" at the beginning, that means a is a substring of those string and need to match from beginning.
So, for this case, answer will be 1.1.1.1 and 1.1.2.4 but not 1.5.1.1 as here 1.1 is not at the beginning.
I know, how to achieve this but I think my solution is not efficient enough and for large arraylist, it will take more processing time.
My approach: Run a for loop for the arraylist and for each string, crop the string from the beginning with the lenth of a and check if cropped string is equal with a.
But if I want to repeat this for several strings for a large arraylist, I think it is not a good solution.
Any idea? I will highly appreciate your help.
startsWith(String str)method of theStringclassstartsWith(String s)instead. Have a look