如何初始化静态数组?
2022-08-31 13:19:50
我见过在Java中定义静态数组的不同方法。也:
String[] suit = new String[] {
"spades",
"hearts",
"diamonds",
"clubs"
};
...或仅
String[] suit = {
"spades",
"hearts",
"diamonds",
"clubs"
};
或作为List
List suit = Arrays.asList(
"spades",
"hearts",
"diamonds",
"clubs"
);
是否有区别(当然,列表定义除外)?
什么是更好的方法(性能明智)?