Is there any built-in method in Java which allows us to convert a string into an list of strings. For eg:
"1,2,3,4" to "1","2","3","4"
Help would be appreciated
Is there any built-in method in Java which allows us to convert a string into an list of strings. For eg:
"1,2,3,4" to "1","2","3","4"
Help would be appreciated
Yeah, using the split
method
String a = "1,2,3,4";
String[] aa = a.split(",");
Into a list:
List<String> aaa = Arrays.asList(aa);
You can create String[]
by split "1,2,3,4"
by ,
. Then convert that in to List
by Arrays.asList()
String str="1,2,3,4";
String[] arr=str.split(",");
List<String> list=Arrays.asList(arr);
String s = "1,2,3,4";
String[] tokens = s.split(",");
List<String> tokenlist=Arrays.asList(tokens);
You can use split method on String.
String str = "1,2,3,4";
String[] listStr = str.split(",");