Answer the question
In order to leave comments, you need to log in
HashMap - how to get the value?
There is a code:
package com.company;
import java.util.ArrayList;
import java.util.HashMap;
public class Main {
public static String URL = "url";
public static String TITLE = "title";
public static void main(String[] args ){
ArrayList<HashMap<String ,String>> Sites = new ArrayList<>();
HashMap<String,String> hashMap;
hashMap = new HashMap<>();
hashMap.put(URL,"http://google.com");
hashMap.put(TITLE,"Google");
Sites.add(hashMap);
hashMap = new HashMap<>();
hashMap.put(URL,"http://yandex.com");
hashMap.put(TITLE,"Yandex");
Sites.add(hashMap);
hashMap = new HashMap<>();
hashMap.put(URL,"http://Yahoo.com");
hashMap.put(TITLE,"Yahoo");
Sites.add(hashMap);
for(int i = 0; i <Sites.size(); i++ ){
System.out.println(Sites.get(i));
}
}
}
{title=Google, url= http://google.com}
{title=Yandex, url= http://yandex.com}
{title=Yahoo, url= http://Yahoo.com}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question