英文:
how to assign a value to a list in java if i assign a following value it shows cannot convert from int[] to List<Integer>
问题
public class GetAddonProductsProcessorTest {
@Test
public void AddonProductstest() throws Exception{
//BasicDBList newobj = new BasicDBList();
List<Integer> newobj = Arrays.asList(1, 2, 3);
}
}
英文:
How to assign a value to a list in java? If Ii assign a following value it shows cannot convert from int[] to List<Integer>
public class GetAddonProductsProcessorTest {
@Test
public void AddonProductstest() throws Exception{
//BasicDBList newobj = new BasicDBList();
List<Integer> newobj = {1,2,3};
}
答案1
得分: 1
你可以使用 Arrays.asList 创建列表
ArrayList<Integer> newObj = new ArrayList(Arrays.asList(new Integer[]{1,2,3}));
英文:
You can create list using Arrays.asList
ArrayList<Integer> newObj = new ArrayList(Arrays.asList(new Integer[]{1,2,3}));
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论