Java study notes-Collections.singletonList usage

 

Collections.singletonList() returns an immutable collection, but the length of the collection is only 1, which can reduce memory space. But the returned value is still the internal implementation class of Collections, and there is also no add method. Calling the add and set methods will report an error.

 

test

public class Test {

   public static void main(String[] args){
       List<String> list=Collections.singletonList("111");
       System.out.println(list);
   }

}

Output:

Guess you like

Origin blog.csdn.net/mumuwang1234/article/details/110872656