Results 1 to 5 of 5
  1. #1
    crank6015 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default help!, while loop wont stop!

    hello, i'm trying to iterate hashmap with while loop, when i send the hashmap to system.out, it gives me the object, when i look at its size, it says 1013.
    so the hashmap is fine i think.
    here's the code
    Java Code:
    int i = 0;
    Iterator hashIterator = hMap.keySet().iterator();
    while(hashIterator.hasNext()){
    i++
    }
    is the while loop right?, because in system out, the i++ never stops.
    and like i said before if i try system.out on the hMap.keySet, it gives me all my key set.

    any idea??

  2. #2
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    Your condition will either be false or it will always be true. You never actually iterate over anything.

  3. #3
    crank6015 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

    Default

    thanks, i understand, so what do i have to add into the while to iterate?
    is it remove item every loop?

  4. #4
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,807
    Rep Power
    10

    Default

    You have created an Iterator. Why not take a look at what methods it has.

  5. #5
    crank6015 is offline Member
    Join Date
    Mar 2011
    Posts
    8
    Rep Power
    0

Similar Threads

  1. Why Wont This Work???
    By Billywizz in forum New To Java
    Replies: 11
    Last Post: 03-09-2011, 03:33 AM
  2. Replies: 7
    Last Post: 11-22-2010, 03:38 PM
  3. The outer loop doesnt stop running
    By Bulelakes in forum JDBC
    Replies: 16
    Last Post: 08-23-2010, 09:42 AM
  4. Use stop button to stop moving (stop timers) on JPanel
    By mneskovic in forum New To Java
    Replies: 3
    Last Post: 07-23-2010, 12:50 PM
  5. why wont it compile
    By bje98f in forum Advanced Java
    Replies: 1
    Last Post: 04-23-2009, 10:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •