How to Convert List to List<Object>

前端 未结 7 1385
忘了有多久
忘了有多久 2020-11-30 03:47

I want to convert List to List.

One of the existing methods is returning List and I

7条回答
  •  迷失自我
    2020-11-30 04:21

    Pass the List as a parameter to the constructor of a new ArrayList.

    List objectList = new ArrayList(stringList);
    
    
    

    Any Collection can be passed as an argument to the constructor as long as its type extends the type of the ArrayList, as String extends Object. The constructor takes a Collection, but List is a subinterface of Collection, so you can just use the List.

    提交回复
    热议问题