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>

huangapple go评论74阅读模式
英文:

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&lt;Integer&gt;

public class GetAddonProductsProcessorTest {

  @Test
  public void AddonProductstest() throws Exception{
    
    //BasicDBList newobj = new BasicDBList();
      
    List&lt;Integer&gt; 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&lt;Integer&gt; newObj = new ArrayList(Arrays.asList(new Integer[]{1,2,3}));

huangapple
  • 本文由 发表于 2020年9月4日 20:39:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/63741377.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定