In java I got 2 strings (each contains a list of words for example ab,ac,ad,bb,bc,bd and second string which contains user input (for example word "a") I want to compare those 2 strings and get text that first string contain (like if startswith return true I want to print out word that matches for example in my case ab,ac,ad) anyone know how can I do it ?
Asked
Active
Viewed 1,526 times
1 Answers
2
Use split
and iterate
String input = "a";
String str = "ab,ac,ad,bb,bc,bd";
for (String s: str.split(",")) {
if (s.startsWith(input)) {
System.out.println("String " + s + " starts with " + input);
}
}

Alex
- 25,147
- 6
- 59
- 55
-
Thank you Alex, this was what I mean :D – user2121038 Feb 28 '13 at 20:01