Hidden Features of Java - ArrayList / instance initializers clarification
List<Integer> numbers = new ArrayList<Integer>(){{ add(1); add(2); }};
I don't really recommend this approach, as it creates an (anonymous) class for no good reason.
Use either:
List<Integer> numbers = Arrays.asList(1, 2);
or
List<Integer> numbers = new ArrayList<Integer>(Arrays.asList(1, 2));
For 2 levels, you can use:
List<List<Integer>> numbers = Arrays.asList(Arrays.asList(1, 2), Arrays.asList(2,3,4));
With a static import you could even reduce it to this, if you really want to:
List<List<Integer>> numbers = asList(asList(1, 2), asList(2,3,4));
Hidden Features IntelliJ IDEA
I love syntax-aware selection. Control + W.
When I'm forced to work with other IDEs, that key sequence usually causes files to close. It's a nasty negative feedback loop.
Related Topics
Converting Array to List in Java
Initial Bytes Incorrect After Java Aes/Cbc Decryption
How to Know If Other Threads Have Finished
Remove Diacritical Marks (Ń Ǹ Ň ñ Ṅ Ņ Ṇ Ṋ Ṉ ̈ Ɲ Ƞ ᶇ ɳ ȵ) from Unicode Chars
How to Supply Value to an Annotation from a Constant Java
How to Read a Specific Line Using the Specific Line Number from a File in Java
Java - Method Name Collision in Interface Implementation
Get a Resource Using Getresource()
How to Check If the User Is Pressing a Key
How to Decrypt File in Java Encrypted with Openssl Command Using Aes
How to Get the Exact Middle of a Screen, Even When Re-Sized
How to Convert a Stack Trace to a String
Differencebetween Serializable and Externalizable in Java
What Is the Easiest/Best/Most Correct Way to Iterate Through the Characters of a String in Java
Comparing Strings with == Which Are Declared Final in Java