Answers for "how to cast Object[] to a list in java"

5

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.
Posted by: Guest on October-06-2021

Code answers related to "how to cast Object[] to a list in java"

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language