利用Collection.of()构造生成一个不可变的集合。
/** nowjava.com - 时 代 Java 提供 **/ import java.util.ArrayList; import java.util.List; import java.util.Map; public class Main { public static void main(String[] args){ List<String> jvmLanguages = List.of("Java", "Scala", "JRuby", "Groovy", "Jython", "Kotlin"); System.out.println(jvmLanguages); try { jvmLanguages.add("Exception"); } catch (UnsupportedOperationException uoe){ System.out.println(uoe);/** n o w j a v a . c o m - 时 代 Java 提 供 **/ } Map <Integer, String> players = Map.of(1, "Ana Bates", 2, "Lady Mary", 3,