How to Convert List to List<Object>

前端 未结 7 1377
忘了有多久
忘了有多久 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<String> as a parameter to the constructor of a new ArrayList<Object>.

    List<Object> objectList = new ArrayList<Object>(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<String>.

    0 讨论(0)
提交回复
热议问题