Skip to content

Instantly share code, notes, and snippets.

@lyo
Last active August 3, 2025 14:00
Show Gist options
  • Select an option

  • Save lyo/e076b822ca0451e983a2dc2b7a78c0dc to your computer and use it in GitHub Desktop.

Select an option

Save lyo/e076b822ca0451e983a2dc2b7a78c0dc to your computer and use it in GitHub Desktop.
java sample code
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