Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

how to convert object to list in java

//Assuming that your object is a valid List object, you can use: Collections.singletonList(object) -- Returns an immutable list containing only the specified object.

List<Object> list = Collections.singletonList(object);
//If you want it in a specific datatype, use Stream.of(object):

List<String> list = Stream.of(object).map(Object::toString).collect(Collectors.toList())
//Similarly, you can change the method in the map to convert to the datatype you need.
 
PREVIOUS NEXT
Tagged: #convert #object #list #java
ADD COMMENT
Topic
Name
3+6 =