Online Java Compiler By
JavaTpoint.com
import java.util.*; public class CollectionsSingletonListExample2 { public static void main(String[] args) { //Create an array of string objects String str[] = { "One", "Two", "Three", "One", "Two", "Three", "JavaTpoint" }; //Create one list List
list = new ArrayList
(Arrays.asList(str)); System.out.println("List value before: "+list); //Create singleton list list = Collections.singletonList("One"); System.out.println("List value after: "+list); } }
Output