Pages

Monday 22 August 2016

How to Covert Comma separated String into a Array or into a List in java!!

Converting Comma separated String into an Array:


String string = "hello,world,this,is,a,string";
String[] stringArray = string.split(",");  //the separator can be any character


Convert Comma separated String into a List:

String string = "hello,world,this,is,a,string";
String[] stringArray = string.split(",");  //the separator can be any character
List<String> list = Arrays.asList(stringArray);


Can be re written in one line

String string = "hello,world,this,is,a,string";
List<String> list = Arrays.asList(string.split(","));



No comments:

Post a Comment