packagecom.dbsy.test;publicclassChangeArgs{publicstaticvoidmain(String[] args){int sum =getSum(6,7,2,12,2021);System.out.println(sum);//2048}publicstaticintgetSum(int...arr){int sum=0;for(int i : arr){
sum+=i;}return sum;}}
往集合中添加一些参数
packagecom.dbsy.test;importjava.util.ArrayList;importjava.util.Collection;importjava.util.Collections;publicclassDou{publicstaticvoidmain(String[] args){ArrayList<Integer> list =newArrayList<>();Collections.addAll(list,6,7,8,9);System.out.println(list);//[6, 7, 8, 9]}}
可变参数package com.dbsy.test;public class ChangeArgs { public static void main(String[] args) { int sum = getSum(6,7,2,12,2021); System.out.println(sum);//2048 } public static int getSum(int...arr){ int sum=0; fo