728x90
put(K key, V value):V
size():int
remove(Object key):V
remove(Object key, Object value):boolean
replace(K key, V value):default V
replace(K key, V oldValue, V newValue):boolean
// TreeMap
//
System.out.println("=====TreeMap=====");
// TreeMap<String,pModelVo03> tm = new TreeMap<>();
TreeMap<String,pModelVo03> tm = new TreeMap<>(hm);
System.out.println(tm); // {내=으샤으샤[2원], 라=으랴차차[3원], 힘=아자아자[1원]}
// size():int
System.out.println(tm.size()); // 3
// remove(Object key):V
// System.out.println(tm.remove(new TreeMap("힘"), new TreeMap("아자아자",1)));
System.out.println(tm.remove(new String("힘"))); // value리턴 : 아자아자[1원]
System.out.println(tm); // {내=으샤으샤[2원], 라=으랴차차[3원]}
System.out.println(tm.keySet());
Set<String> set = tm.keySet();
Iterator<String> itr = set.iterator();
while(itr.hasNext()) {
String str = itr.next();
System.out.println(str);
}
System.out.println(tm.remove(new String("내")));
System.out.println(tm); // {라=으랴차차[3원]}
System.out.println("===replace===");
// replace(K key, V oldValue, V newValue):boolean
System.out.println(tm.replace(new String("라"), new pModelVo03("으랴차차",3), new pModelVo03("화이팅",4)));//true
// remove(Object key, Object value):boolean
tm.remove(new String("라"), new pModelVo03("화이팅",4));
System.out.println(tm); // {}
System.out.println("===TreeMap2===");
TreeMap<String,pModelVo03> tm2 = new TreeMap<>();
// put(K key, V value):V
tm2.put(new String("a"), new pModelVo03("a",1));
tm2.put(new String("b"),new pModelVo03("b",2));
tm2.put(new String("c"),new pModelVo03("c",3));
System.out.println(tm2); // {a=a[1원], b=b[2원], c=c[3원]}
// size():int
System.out.println(tm2.size()); // 2
// remove(Object key):V
System.out.println(tm2.remove(new String("b"))); // 지운 밸류값 출력 : b[2원]
System.out.println(tm2); // {a=a[1원], c=c[3원]}
// remove(Object key, Object value):boolean
System.out.println(tm2.remove(new String("a"),new pModelVo03("a",1)));// true
System.out.println(tm2); // {c=c[3원]}
// replace(K key, V value):default V
System.out.println(tm2.replace(new String("c"), new pModelVo03("c",3))); // c[3원]
// replace(K key, V oldValue, V newValue):boolean
tm2.replace(new String("c"), new pModelVo03("c",3), new pModelVo03("d",4));
System.out.println(tm2.replace(new String("c"), new pModelVo03("c",3), new pModelVo03("d",4)));//false
System.out.println(tm2); // {c=d[4원]} : 키값c 밸류값d,4
728x90
반응형
'small steps > 1일 1코딩 - 코딩을 내 몸처럼' 카테고리의 다른 글
[1일1코딩] [Java] 인터페이스 HashMap, TreeMap (0) | 2022.03.08 |
---|---|
[1일1코딩] [Java] Collection - Map - HashMap (0) | 2022.03.07 |
[1일1코딩] [Java] Interface Set - HashSet, TreeSet, LinkedHashSet (0) | 2022.03.05 |
[1일1코딩] [Java] ArrayList의 메소드 : add,remove,contains, indexOf, get,set (0) | 2022.03.04 |
[1일1코딩] [Java] LinkedHashSet, HashSet, TreeSet (0) | 2022.03.03 |