0

I am trying to loop through a hashmap which contains Sessions and IDs. Multiple sessions may have the same ID. On each method call, I need to iterate through the hashmap and find which sessions are listed against a given ID.

class contains:

private static Map<Session, String> peers = new HashMap<Session, String>    ();

Method contains:

for (Map.Entry<Session, String> entry : peers.entrySet()) {
                if(entry.getValue() == clientId){
                    Session peer = entry.getKey();
                    peer.getBasicRemote().sendObject(figure);
                   }
            }

But the problem is it runs only one time. Even I tried to get the size of hashmap and it given the exactly amount what I have.

1
  • You should compare strings with equals if(entry.getValue().equals(clientId)){ Commented Mar 25, 2015 at 18:37

1 Answer 1

1

As the value is a String, you should probably compare it via equals(), as == only checks if two objects are the same object, but not if they are the same String. But that's only guessing.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.