[java] How to initialize a static array?

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

The answer is


Nope, no difference. It's just syntactic sugar. Arrays.asList(..) creates an additional list.


Examples related to java

Under what circumstances can I call findViewById with an Options Menu / Action Bar item? How much should a function trust another function How to implement a simple scenario the OO way Two constructors How do I get some variable from another class in Java? this in equals method How to split a string in two and store it in a field How to do perspective fixing? String index out of range: 4 My eclipse won't open, i download the bundle pack it keeps saying error log

Examples related to arrays

PHP array value passes to next row Use NSInteger as array index How do I show a message in the foreach loop? Objects are not valid as a React child. If you meant to render a collection of children, use an array instead Iterating over arrays in Python 3 Best way to "push" into C# array Sort Array of object by object field in Angular 6 Checking for duplicate strings in JavaScript array what does numpy ndarray shape do? How to round a numpy array?

Examples related to static

What is the equivalent of Java static methods in Kotlin? Creating a static class with no instances Static vs class functions/variables in Swift classes? Call static methods from regular ES6 class methods What is the difference between static func and class func in Swift? An object reference is required to access a non-static member Mocking static methods with Mockito @Autowired and static method The static keyword and its various uses in C++ Non-Static method cannot be referenced from a static context with methods and variables

Examples related to playing-cards

How to initialize a static array?