티스토리 뷰
Map
- SortedMap
- TreeMap
- HashTable
- LinkedHashMap
- HashMap
Interface Map<K,V>
Map<String, Integer> new = new HashMap<String, Integer>();
Map.Entry<K,V>
Map<String,Integer> map = new HashMap<String,Integer>();
map.put("apple",1);
map.put("tomato",2);
map.put("banana",3);
Set<Map.entry<String,Integer>> entries=map.entrySet();
for(Map.entry<String,Integer> entry:entries){
Sytem.out.println(entry.getKey()+", "+entry.getValue())
}
//apple, 1
//tomato, 2
//banana, 3
HashMap.forEach()
public void forEach(Biconsumer<? super K, ? super V> action)
// Biconsumer is a functional interface that takes two arguments and does not return.
Map<String,Integer> map = new HashMap<String,Integer>();
map.put("apple",1);
map.put("tomato",2);
map.put("banana",3);
map.forEach((key,value)
-> System.out.println("key : "+key+", value : "+value)
);
map.entrySet().forEach((entry)
-> System.out.println("key : "+entry.getKey()+", value : "+entry.getValue())
//key : apple, value : 1
//key : tomato, value : 2
//key : banana, value : 3
'개발 > Java' 카테고리의 다른 글
[프로젝트][blog] OptimisticLock (동시성 이슈) (1) | 2023.12.22 |
---|---|
[Spring boot] 실행 가능 Jar (0) | 2023.05.19 |
[Java] Scanner(화면에서 입력받기) (0) | 2023.01.13 |
[Java] 예외처리(exception handling) (0) | 2023.01.11 |
[Java] 연산자(operator) (0) | 2022.12.27 |
최근에 올라온 글
- Total
- Today
- Yesterday