1. LRUMap Example
Download: apache commons collections
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | package javautility; import java.io.IOException; import java.util.Map; import org.apache.commons.collections4.map.LRUMap; public class JavaUtility { static void testLRUMapExplicit() { Map<String,String> map = new LRUMap(2); map.put("3","C"); map.put("2","B"); map.put("1","A"); for(Map.Entry<String,String> m : map.entrySet() ) { //don't use keySet() System.out.println(m.getKey() + "," + m.getValue()); } } static void testLRUMapImplicit() { LRUMap map = new LRUMap(2); map.put("3","C"); map.put("2","B"); map.put("1","A"); for( Object m : map.entrySet() ) { Map.Entry<String,String> e = (Map.Entry<String,String>)m; System.out.println(e.getKey() + "," + e.getValue()); } } public static void main(String[] args) throws IOException { testLRUMapExplicit(); System.out.println("----------"); testLRUMapImplicit(); } } |
Result:
2,B 1,A ---------- 2,B 1,A
댓글 없음:
댓글 쓰기