• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

HashMap, Iteraring problem

 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys,

I have a HashMap, and it stored a bunch of Strings... the key is a String and the value is a Set of String...

and it looks something like this

{ D=[E,C], C=[B], E=[B], B=[A] }

what is the best way to iterate through this map so i get the two list. i.e.

D-E-B-A and the other would be D-C-B-A
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess we found D->E, then E->B then B->A? Try writing down what we did in plain English:

Hmmm, that didn't turn out very "plain" because it could keep repeating itself like that.

The solution that comes to mind for me involves "recursion". Are you familiar with how that works? If not, we could go there next.
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
not really... someone mentioned something about recursion method... im not familiar with this
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OP is getting some useful help here, so probably not worth explaining recursion again.
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I modified the code(here) slightly so it compiles with 1.4 (without the generics)
and i also havent come accross the

Arrays.asList

method so i rebuild the graphI'm sticking to what i know for now. so now the code looks like this...




and the output i get is null pointer exception...
why is that?


[ October 02, 2006: Message edited by: Firman Drage ]
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok its solved again... here
 
This one time, at bandcamp, I had relations with a tiny ad.
New web page for Paul's Rocket Mass Heaters movies
https://coderanch.com/t/785239/web-page-Paul-Rocket-Mass
reply
    Bookmark Topic Watch Topic
  • New Topic