How to Convert List to List<Object>

前端 未结 7 1405
忘了有多久
忘了有多久 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:04

    If you are willing to convert to an unmodifiable List, you can simply wrap your list with Collections.unmodifiableList. This works because this static method has a proper wildcard type ? extends T for the element type of the wrapped list (where T is the type of the result list).

    Note that, in most cases, creating an unmodifiable view is what you should do, otherwise objects of different types (other than String) may be added in the original list (which should only hold Strings).

    提交回复
    热议问题