Is there a shortcut syntax in Java to create and initialize an ArrayList, much like one does for an Array?
-
I want to make an ArrayList in Java quick and easy with one line of code. To do this with an array i would simply type: 1. int[] array = { 1, 2, 3 }; Is there an equivalent for ArrayLists? To clarify, one would usually type: 1. ArrayList<Integer> arrayList = new ArrayList<Integer>(); 2. arrayList.add(1); 3. arrayList.add(2); 4. arrayList.add(3); Is there a shorter way?
-
Answer:
Use a unnamed code block. This unnamed block is executed after the instance is created .
Zach at Yahoo! Answers Visit the source
Related Q & A:
- how to create a new syntax in java?Best solution by Stack Overflow
- How much for one Company website in your area?Best solution by Yahoo! Answers
- How much is one text on a tracfone?Best solution by tracfone.com
- How can I create a shortcut to yahoo mail on my desktop?Best solution by Yahoo! Answers
- Is physical seeing much like a photographic/camera picture taking? Why?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.