가능한 중복 : 나는 다음 코드 조각을 작성한와 해시 맵의 반복에 부착하고
How do I iterate over each Entry in a Map?
How can I iterate over a map of <String, POJO>?순회 해시 맵을 통해
. 이 코드에서
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
class demo
{
public static void main(String v[]) {
ArrayList<String> contactIds = new ArrayList<String>();
contactIds.add("2");
contactIds.add("3");
HashMap names = new HashMap();
names = getNames(contactIds);
// I want to get the total size of the hashmap - names
// for ex now there are 6 elements inside hashmap.
// How can I get that count?
}
private static HashMap getNames(ArrayList contactIds) {
HashMap names = new HashMap();
String params = null;
List<String> list = new ArrayList<String>();
for(int i=0; i<contactIds.size();i++) {
params = contactIds.get(i).toString();
list.add(0,"aer-1");
list.add(1,"aer-2");
list.add(2,"aer-3");
names.put(params,list) ;
}
return names;
}
}
, 여섯 elments 내가지도를 반복하고 총 수를 얻을 수있는 방법의 주요 방법 지금,지도 내부에있다?
감사합니다.
그러나 어떻게 hashmap 내에있는 요소의 총 개수를 얻을 수 있습니까? 예를 들어 키 1과 키 2에 3 개의 요소가 추가되었습니다. 이제 전체 크기 즉 6을 원했습니다. 그것은 가능한가? – nithin