• Post Reply Bookmark Topic Watch Topic
  • New Topic

Accessing ArrayList<ArrayList<Integer,String> elements  RSS feed

 
Matt Wright
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a data structure such as: ArrayList<ArrayList<Integer,String>

The data looks as [[1,2,3] [3,4] [99,98,40,32,45,65,1]]

I am trying to access each element and put them into a hashtable such as:

Hashtable<Integer,String>

With what I am doing below I am getting an out of bound error but can't see any other way of accessing the element

 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 37513
554
Eclipse IDE Java VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Almost. The problem lies in this line:


It gets the size of the outer list. But for the inner loop, you want the size of the inner list.
 
Matt Wright
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh wow! It's the simple mistakes that take the most time. Thank you very much!
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure about the generic type?
ArrayList<ArrayList<Integer,String>??
That should really read List<List<Integer,String> but even that looks incorrect. It should end with a second > (minor problem) and the inner <> should only contain one name because List is defined as List<E>.
I think it should be List<List<String>> or List<List<Integer>>
What you printed looks more like Integers to me.

It is possible that the forum software is messing up you <s and >s. That error has occurred before.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
By the way: use HashMap in preference to Hashtable. Look in the Java Tutorials, particularly the sections about Map interface and Map implementations.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!