Reputation: 647
I am building online music application in android and I am using HashMap. it has method method ie:-
hashmap.put<String,URL>
example:
HashMap<String,URL> urlHashMap=new HashMap<String,URL>();
urlHashMap.put("Manali Trance",http://newmp3mad.com/128-734892s/Manali%20Trance.mp3);
It is not allowing me to put URL. Please someone help.
Upvotes: 0
Views: 802
Reputation: 17879
Use Uri (or URL) type for your hashmap types : so it will be String/Uri
HashMap<String, Uri> hashmap = new HashMap<>();
hashmap.put("Queen", Uri.parse("http://queen.com/you.mp3"));
Import information : use Uri from android.net
Upvotes: 3
Reputation: 8774
You can also just use your URL as a string literal like so:
urlHashMap.put("Manali Trance","http://newmp3mad.com/128-734892s/Manali%20Trance.mp3");
Java doesn't have URL literal types. Whether using a string or parse as a URI depends entirely on what you're trying to do.
Upvotes: 0