📌  相关文章
📜  如何在java代码示例中将对象转换为列表

📅  最后修改于: 2022-03-11 14:52:24.337000             🧑  作者: Mango

代码示例1
//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 list = Collections.singletonList(object);
//If you want it in a specific datatype, use Stream.of(object):

List 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.