I have seen different approaches to define a static array in Java. Either:
String[] suit = new String[] {
"spades",
"hearts",
"diamonds",
"clubs"
};
...or only
String[] suit = {
"spades",
"hearts",
"diamonds",
"clubs"
};
or as a List
List suit = Arrays.asList(
"spades",
"hearts",
"diamonds",
"clubs"
);
Is there a difference (except for the List definition of course)?
What is the better way (performance wise)?
This question is related to
java
arrays
static
playing-cards
Nope, no difference. It's just syntactic sugar. Arrays.asList(..)
creates an additional list.
Source: Stackoverflow.com