非常に便利なものがありますArrays.asList()
:
public static <T> List<T> asList(T... a) {
return new ArrayList<T>(a);
}
しかし、ありませんArrays.array()
:
public static <T> T[] array(T... values) {
return values;
}
非常に些細なことですが、これは配列を構築するための非常に便利な方法です。
String[] strings1 = array("1", "1", "2", "3", "5", "8");
// as opposed to the slightly more verbose
String[] strings2 = new String[] { "1", "1", "2", "3", "5", "8" };
// Of course, you can assign array literals like this
String[] strings3 = { "1", "1", "2", "3", "5", "8" };
// But you can't pass array literals to methods:
void x(String[] args);
// doesn't work
x({ "1", "1", "2", "3", "5", "8" });
// this would
x(array("1", "1", "2", "3", "5", "8"));
以外の Java 言語のどこかにそのようなメソッドはありjava.util.Arrays
ますか?