Last active
August 3, 2025 14:00
-
-
Save lyo/e076b822ca0451e983a2dc2b7a78c0dc to your computer and use it in GitHub Desktop.
java sample code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package test; | |
| import java.util.LinkedHashMap; | |
| import java.util.Map; | |
| public class LinkedHashMapTest extends LinkedHashMap { | |
| private static final long serialVersionUID = 8641341953159332320L; | |
| private static final int MAX_ENTRIES = 3;//貯め込められるのは3まで。 | |
| @Override | |
| protected boolean removeEldestEntry(Map.Entry eldest) { | |
| return size() > MAX_ENTRIES; | |
| } | |
| /** | |
| * @param args | |
| */ | |
| public static void main(String[] args) { | |
| LinkedHashMapTest m = new LinkedHashMapTest(); | |
| m.put("a",1); | |
| m.put("b",2); | |
| m.put("c",3); | |
| m.put("d",4); | |
| m.put("e",5); | |
| for(String key : m.keySet()){ | |
| System.out.print(key); //結果はcdeとなる | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment