Utility method for wrapping an object in a collection

前端 未结 5 744
抹茶落季
抹茶落季 2021-02-06 22:44

I\'m looking for a static method in the Java core libraries or some other commonly used dependency — preferably one of Apache — that does the following:

public s         


        
5条回答
  •  温柔的废话
    2021-02-06 22:49

    Immutable list in guava

    public static  ImmutableList of(E element)
    

    Returns an immutable list containing a single element. This list behaves and performs comparably to Collections.singleton(T), but will not accept a null element. It is preferable mainly for consistency and maintainability of your code.

提交回复
热议问题