2

folks, how can I add an additional row to the end of the 2D ArrayList? What is the technique for that? Or how should I approach it? I haven't written a code for that because I don't how to start it.

I have a 2D ArrayList which is

ArrayList<ArrayList<T>> myBoard = new ArrayList<ArrayList<T>>(); and would like to add an additional line to its end but do not know how to approach it. My 2D ArrayList looks like the following:

The number of rows is 6
The number of cols is 3
ABC
AAA
BAC
BEC
BEA
BAB

Could please smb help me?

public void addRowBottom(ArrayList<ArrayList<T>> myBoard){
      ArrayList<T> addRow = new ArrayList<T>();

}
0

1 Answer 1

3

List is ordered Collection. When you add to the list it already adds at end. That will the highest indexed element in the list.

public void addRowBottom(ArrayList<ArrayList<T>> myBoard){
      ArrayList<T> addRow = new ArrayList<T>();
      //add data to addRow
      myBoard.add(addRow);
}
Sign up to request clarification or add additional context in comments.

4 Comments

@Michael Yes. Try and see ;)
@SureshAtta, thanks for the response! One more question: to add a column in the end, should I run a loop through the myBoard and add an empty space in the end of each line? I'd appreciate it!
@Michael You should ask that as a new question. Anyways, what do you mean by empty space in the end of each line ?
@SureshAtta, I will ask it as a new question soon if I do not figure out it on my own. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.