?
Solved

Element in arraylist of arraylists

Posted on 2013-11-19
2
Medium Priority
?
286 Views
Last Modified: 2013-11-19
Working in Java, how do I address a specific item in an array list of arraylists?

I have the constructor:
ArrayList<ArrayList<Integer>> testpaths = new ArrayList<ArrayList<Integer>>();

Which when I print to console:
System.out.println(testpaths + "\n");

Output after running some method() is:
[[], [1], [2], [1, 5, 3], [2, 4], [1, 5], [1, 5, 6], [1, 5, 7]]

Let's say that in that 8th item [1,5,7] - I just want the "1".

Thanks!
0
Comment
Question by:Geisrud
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 14

Accepted Solution

by:
jb1dev earned 2000 total points
ID: 39661102
testpaths.get(7).get(0);
0
 
LVL 14

Expert Comment

by:jb1dev
ID: 39661112
The above should work fine provided you have the generics in place, as you do in your example. If you did not have the generics in place, you would need to cast the first get() result back as an ArrayList.

E.g.
((ArrayList)testpaths.get(7)).get(0);
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question