Add Collections#singletonList

This is a very dumb implementation that wastes space and time by
constructing a full-blown ArrayList as backend. However, it is
better to have a dumb implementation than none at all, and we can
always do something about the performance when, and if, that should
become necessary.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
This commit is contained in:
Johannes Schindelin 2013-10-25 13:28:18 -05:00
parent 86c735e649
commit 056c65947e

View File

@ -659,4 +659,10 @@ public class Collections {
return - cmp.compare(o1, o2);
}
}
public static <T> List<T> singletonList(T o) {
ArrayList<T> list = new ArrayList<T>(1);
list.add(o);
return new UnmodifiableList(list);
}
}