How do you create a Two-Dimensional ArrayList?

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

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

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.