java - inserting element in 2D Array List -


I am trying to insert an element in an ArrayList. Elements are not being added and why I am not able to.

What do I have here:

t [0] [0] => account

t [0] [1] => balance

  Class Banking 4 {Int i = 0; Array List [] [] T = New Array List [2] [10]; Scanner sc = new scanner (System.in); Zero addAccount () {for (int i = 0; i & lt; t.length; i ++) {if (t [i] [0] == faucet) {System.out.println ("Enter the account number : "); Int a = sc.nextInt (); T [0] [0] = new arrelist (); T [0] [0] .add (a); T [0] [1] = new Arrivits (); T [0] [1] .add (0); System.out.println ("The account number is:" + a + "Current balance:" + t [0] [1]); break; }}}}}  

ArrayList is not an array type to treat it in a way Instead you need to make nested arrives.

  // Create ArrayList & lt; ArrayList & lt; FooBar & gt; & Gt; List = New Arrestist & lt; ArrayList & lt; FooBar & gt; & Gt; (); // Add to the first layer list. Set (index, new arreelist & lt; FooBar & gt; ()); // Add to the second layer list. (Index 1) .set (index 2, new buffer ()); // etc  

So basically you need to use get () on the first list to access the second layer of the straightforward list.


Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

lua - HowTo create a fuel bar -