可变参数的使用:
代码如下:
package CanChangePack;import java.util.Arrays;
import java.util.List;public class ArgsDemo01 {public static void main(String[] args){List<String> list = Arrays.asList("hello","world","java");//无法进行list.add(),list.remove()操作。list.set(1,"hi");System.out.println(list);}}
package CanChangePack;import java.util.List;public class ArgsDemo01 {public static void main(String[] args){List<String> list = List.of("hello", "world", "java","world");//不支持list.add(),list.remove(),list.set()操作。System.out.println(list);}}
package CanChangePack;import java.util.Set;public class ArgsDemo01 {public static void main(String[] args){//不允许重复元素Set<String> set = Set.of("hello","world","java");//不支持set.add(),set.remove()System.out.println(set);}}