1

I am trying to store hyperlink as a key in map , i am using multimap

 private Map<String, List<String>> record=new HashMap<String, List<String>>(); 

and i am using following way to check whether the hyperlink is already exist in the map or not

 record.containsKey(url) 

But even if the url is exist in a map , it is returning false for the same url which is already there in the map. so how can i solve this issue

the link i am storing is

 http://101.13.20.343/test/wav/uploads/372.wav 
4
  • 5
    There is no reason why it would not work. Try and post an SSCCE that replicates your issue. Commented Apr 24, 2012 at 20:03
  • 1
    Works just fine: ideone.com/DASDf Commented Apr 24, 2012 at 20:05
  • 2
    Try printing your map keys with prefixed and suffixed with ---key--- and if you see a space between them, then the blank space will be the issue. Commented Apr 24, 2012 at 20:10
  • Hell , i was adding keys inside a inner loop so thts why it was create a new object every time my mistake but +1 for all the efforts Commented Apr 24, 2012 at 20:17

2 Answers 2

2

This works for me :

public static void main(String[] args) { Map<String, List<String>> record=new HashMap<String, List<String>>(); record.put("http://101.13.20.343/test/wav/uploads/372.wav", new ArrayList<String>()); System.out.println(record.containsKey("http://101.13.20.343/test/wav/uploads/372.wav")); } 
Sign up to request clarification or add additional context in comments.

Comments

2

Did you trim the whitespaces at each end? In some cases, this might be it?

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.