Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
12/17/2011 11:24:50 AM EDT
Assuming your pulling the contents of an object from a hashmap key <Key, Object(s)>, the default while key.hasnext print keys.next prints like this:

[Object 1, Object 2]

How can I get it to print like a list? :

Object 1
Object 2

I've already got the program running perfect, I just can't figure out how to change from the default printout. I'm printing it something like Key \n Object \n Object \n Key \n Object etc.
12/17/2011 11:54:37 AM EDT
[#1]
Java and "print"?

Why not just handle the output yourself?
12/17/2011 12:55:37 PM EDT
[#2]






while(iterator.hasNext()){
   System.out.println(iterator.next());

}

 
12/17/2011 2:37:33 PM EDT
[#3]
Quoted:

while(iterator.hasNext()){
   System.out.println(iterator.next());
}
 


I'm using an iterator, the .next is what's printing
[Object 1, Object 2]
12/17/2011 2:39:10 PM EDT
[#4]
Quoted:
Java and "print"?

Why not just handle the output yourself?


I'm using an iterater to handle the output, I just can't seem to iterate the individual Objects inside of a key. I can properly display the keys, and their "group" of objects, I want to display the objects individually under the key.
12/17/2011 2:53:57 PM EDT
[#5]

Quoted:
Quoted:













while(iterator.hasNext()){
   System.out.println(iterator.next());



}
 

I'm using an iterator, the .next is what's printing



[Object 1, Object 2]





So each item in your hashmap is another set of some type? You will need to iterate the object set that is being returned in the first iteration then.
 









ETA: Assuming your subset is also a hashmap.






while(iterator.hasNext()){

 iterator2 = iterator.next().keySet().iterator();

while(iterator2.hasNext()){

 System.out.println(iterator2.next());

 }

}





 
12/17/2011 2:59:48 PM EDT
[#6]
Quoted:

Quoted:
Quoted:

while(iterator.hasNext()){
   System.out.println(iterator.next());
}
 


I'm using an iterator, the .next is what's printing
[Object 1, Object 2]

So each item in your hashmap is another set of some type? You will need to iterate the object set that is being returned in the first iteration then.


So iterate through without printing, and iterate the block of objects retrieved?

ETA: I see your edit, I think that's what I wasn't getting. My subset isn't a hash, it's a hash for the key's and objects, and each set of objects is an ArrayList.
12/17/2011 3:01:33 PM EDT
[#7]



Quoted:

So iterate through without printing, and iterate the block of objects retrieved?



ETA: I see your edit, I think that's what I wasn't getting.


Yes, I added some poorly formatted code to my previous post.

 
12/17/2011 3:06:09 PM EDT
[#8]
You can iterate the ArrayList the same way as the hashmap.
12/17/2011 3:26:08 PM EDT
[#9]
Ha. It works, but it keeps iterating the last Object set over for all the keys. Instead of

Key1
Object 1
Object 2
Key2
Object3
Object4

It's

Key1
Object 1
Object 2
Key2
Object 1
Object 2
12/17/2011 3:44:08 PM EDT
[#10]
Check the variable assignments.  iterator2 is not being assigned the next incremented item from iterator1.