[JAVA]HASHMAP 돌리기(SORT)

JAVA 2017. 11. 24. 15:37

HASHMAP 돌리기(SORT)



package main.java.com;


import java.util.ArrayList;

import java.util.Collections;

import java.util.Enumeration;

import java.util.HashMap;

import java.util.Iterator;

import java.util.List;

import java.util.TreeSet;

import java.util.Vector;


import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;



public class job{


private static Log logger = LogFactory.getLog(job.class);


public static void main(String[] args){

// TODO Auto-generated method stub

HashMap<String,String> hm = new HashMap<String, String>();


hm.put("01", "01String");

hm.put("02", "02String");

hm.put("03", "03String");

hm.put("04", "04String");

hm.put("05", "05String");

hm.put("06", "06String");


Iterator<String> iter = hm.keySet().iterator();

while(iter.hasNext()){

String cnt = iter.next();

logger.debug(hm.get(cnt));

}


// Sort hashtable.

Vector v = new Vector(hm.keySet());

Collections.sort(v);


for(Enumeration e = v.elements(); e.hasMoreElements();){

String key = (String)e.nextElement();

String val = (String)hm.get(key);

System.out.println("Key: " + key + " Val: " + val);

}


HashMap<Integer,VO> hm2 = new HashMap<Integer, VO>();

for(int i=0; i < 1000; i++){

VO v1 = new VO();

v1.setA1("a"+"_"+i);

v1.setA2("b"+"_"+i);

v1.setA3("c"+"_"+i);

hm2.put(i, v1);

}


logger.debug(hm2.get(100).getA1());

}

}


class VO{

private String a1 = "";

private String a2 = "";

private String a3 = "";


public String getA1(){

return this.a1;

}


public String getA2(){

return this.a2;

}


public String getA3(){

return this.a3;

}


public void setA1(String a1){

this.a1 = a1;

}



public void setA2(String a2){

this.a2 = a2;

}



public void setA3(String a3){

this.a3 = a3;

}

}

'JAVA' 카테고리의 다른 글

[JAVA]https 로 변경  (0) 2017.11.27
[JAVA]html를 이미지로 변환  (2) 2017.11.24
[JAVA]getBean Test Main  (0) 2017.11.24
[JAVA]ftp util  (0) 2017.11.24
[JAVA]filter에서 파라미터 받기  (1) 2017.11.23
블로그 이미지

마크제이콥스

초보 개발자의 이슈및 공부 내용 정리 블로그 입니다.

,