关于java:如何用arraylist替换数组?

How do i replace an array with an arraylist?

本问题已经有最佳答案,请猛点这里访问。

如何用ArrayList替换下面的数组。

1
Employee[] companyTeam = {manager, engineer1, superviso1, accountant, intern };


你可以做一些像

1
List<Employee> companyTeam = Arrays.asList(manager, engineer1, superviso1, accountant, intern);


1
2
 Employee[] companyTeam = {manager, engineer1, superviso1, accountant, intern };
 List<Employee>  list=Arrays.asList(companyTeam);// array to List

您已经有了一个数组,因此可以使用Arrays.asList(companyTeam)将数组转换为List