Mohit Kumar Sharma
Mohit Kumar Sharma

Reputation: 647

how to pass url of a website in Hashmap in android

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

Answers (2)

Hugo Gresse
Hugo Gresse

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

ci_
ci_

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

Related Questions