This week's book giveaway is in the Kotlin forum.
We're giving away four copies of Kotlin in Action and have Dmitry Jemerov & Svetlana Isakova on-line!
See this thread for details.
Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

2D ArrayList and converting to HashMap  RSS feed

 
Saikrishna Vemuri
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one help me in coding a 2D ArrayList and convert it into HashMap.?
Thanks in Advance
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saikrishna Vemuri wrote:Can any one help me in coding a 2D ArrayList and convert it into HashMap.?
Thanks in Advance

Before Campbell starts ranting, I'll set you straight: There is no such thing as a 2D ArrayList.

What you can have is an ArrayList of ArrayLists, which is almost the same thing; and the definition for it would look something like:
List<List<SomeClass>> my2DList = new ArrayList<ArrayList<SomeClass>>();

But how you convert it to a HashMap will depend entirely on how you want to do it; and for that we'll need a lot more information.

Winston
 
Saikrishna Vemuri
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my concern is adding items to the list .
 
Kemal Sokolovic
Bartender
Posts: 825
5
Java Python Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saikrishna Vemuri wrote:my concern is adding items to the list .

Then you should check this first and then come back with more specific problem.
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Saikrishna Vemuri wrote:my concern is adding items to the list .

OK, well firstly, you're going to need to add them in order (or at least it's going to be an awful lot easier), because an ArrayList is NOT an array. To be honest, if this structure is meant to simulate a matrix, I'd suggest that you use a Map rather than a "2D" ArrayList; otherwise just use a plain old 2D array (sorry Campbell), viz:
SomeClass[][] = new SomeClass[10][10];

I think perhaps you need to explain a bit more about what you want to do.

Winston
 
Campbell Ritchie
Marshal
Posts: 55722
163
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote: . . . Before Campbell starts ranting, . . .
That’s 2D arrays I go on about
But you are right; there ain’t no such thing as a 2D ArrayList either.
 
Campbell Ritchie
Marshal
Posts: 55722
163
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Winston Gutkowski wrote:. . . 2D array (sorry Campbell) . . .
I bet you aren’t sorry at all; you are only saying that to wind me up
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!