HashMap에 데이터를 저장하려고하는데 HashMap에 읽는 데이터 소스의 마지막 항목 만 저장할 수있는 것 같습니다. 그 이유는 확실하지 않습니다.HashMap에 데이터 저장 Java
//Loops through the counties and stores the details in a Hashmap
void getCountyDetails(List<Marker>m){
HashMap t = new HashMap();
for(Marker county: countyMarkers){
println("county:" + county.getProperties());
t = county.getProperties();
}
println(t);
}
이 줄 ->println("county:" + county.getProperties());
출력이 :
다음은 내 코드입니다
county:{name=Carlow, pop=54,612}
county:{name=Cavan, pop=73,183}
county:{name=Clare, pop=117,196}
county:{name=Cork, pop=519,032}
county:{name=Donegal, pop=161,137}
county:{name=Dublin, pop=1,273,069}
county:{name=Galway, pop=250,541}
county:{name=Kerry, pop=145,502}
county:{name=Kildare, pop=210,312}
county:{name=Kilkenny, pop=95,419}
county:{name=Laois, pop=80,559}
county:{name=Letrim, pop=31,796}
county:{name=Limerick, pop=191,809}
county:{name=Longford, pop=39,000}
county:{name=Louth, pop=122,897}
county:{name=Mayo, pop=130,638}
county:{name=Meath, pop=184,135}
county:{name=Monaghan, pop=60,483}
county:{name=Offaly, pop=76,687}
county:{name=Roscommon, pop=64,065}
county:{name=Sligo, pop=65,393}
county:{name=Tipperary, pop=158,754}
county:{name=Waterford, pop=113,795}
county:{name=Westmeath, pop=86,164}
county:{name=Wexford, pop=145,320}
county:{name=Wicklow, pop=136,640}
나는 HashMap
에 저장하고 싶습니다.
이 줄 ->println(t);
출력 :
{name=Wicklow, pop=136,640}
이 문제들에 어떤 도움을 주셔서 감사합니다겠습니까. 기본적으로 그것은 단지 해시 맵에 데이터의 목록을 얻고, 현재 그 목록의 마지막 항목에 배치되고있다.
그래서'HashMap.put' 메서드 호출은 어디에 있습니까? –