473,408 Members | 1,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Accessing ArrayList of an ArrayList

sid0404
16
Hi

How do I print elements of an ArrayList of an ArrayList, I think it has to be something similar to a 2 D array, but with a difference, my child arraylist has different number of elements say I have 3 child lists and they have 2, 5, 4 elements when I add them to the parent arrayList, but the number of elements in each child list can vary from time to time, can any one suggest a modular approach towards it ?

Clarification appreciated.
Oct 31 '08 #1
1 1898
JosAH
11,448 Expert 8TB
Why not use the for-each loop? In the next example I assume that your inner
Lists contain Strings; have a look:

Expand|Select|Wrap|Line Numbers
  1. ArrayList<ArrayList<String>> outer= ...; // your outer list
  2. for (List<String> inner : outer) // loop over outer list
  3.    for(String str : inner) // loop over inner list
  4.       // do something with str
  5.  
Of course you can also use an old fashioned for loop:

Expand|Select|Wrap|Line Numbers
  1. ArrayList<ArrayList<String>> outer= ...; // your outer list
  2. for (int i= 0, n= outer.size(); i < n; i++) { // loop over outer list
  3.    List<String> inner= outer.get(i);
  4.    for (j= 0, m= inner.size(); j < m; j++) {
  5.       String str= inner.get(j);
  6.       // do something with str
  7.    }
  8. }
  9.  
Or you can user Iterators (left to the reader for an exercise)

kind regards,

Jos
Oct 31 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

11
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
3
by: Stephen | last post by:
I was wondering if someone can help me with an web application design problem. I have a aspx page which builds up an arraylist called addresses and outputs the values in the arraylist items to a...
5
by: Jack Addington | last post by:
How do I go about accessing elements of an Arraylist using something other than the index? I have a class that manages a number of subclasses. Those subclasses are stored in an arraylist. The...
3
by: JJ | last post by:
Hi, I have created an Arraylist object from an Arraylist class. I added rows to the arraylist object and I need to find a particular record in my arraylist. How do I do this? Also if I was in...
1
by: Ankita | last post by:
Hi I have a webservice which has 2 webmethods: 1.One that returns a String 2.One that returns an ArrayLis I need to use this WebService in VBA environment. I am using the Webservices References...
3
by: Alex | last post by:
Hi all, I'm trying to create an arraylist of a user control class... I'm able to define the list and add objects (panels) to it, but I can access and of the panel properties using an index... ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.