A one-liner code to convert comma-separated Strings to List in Java
Mar 1, 2021
No talking! Let’s just do the code.
// String that is comma separated
String listOfUserIds = “10,11,12,13”;// The magic that converts it to list
List<String> userIds = new ArrayList<String>(Arrays.asList(listOfUserIds.split(“,”)));
To convert the List back to String:
userIdsLists = userIds.join(', ')
Originally published at http://binyit.blogspot.com.