Launch offer
Business website $150 USD Custom plugin $200 USD Ready in 5 days
Get a quote
Java

TreeMap in Java

Store sorted key/value pairs with TreeMap.

TreeMap in Java — a practical guide to Java TreeMap with clear examples you can reuse in real projects.

Java Tutorial Series (56/90). Prefer one article? Read the complete Java tutorial.

Short description

`TreeMap` keeps keys sorted and is useful for range-like ordered maps.

TreeMap

import java.util.TreeMap;

TreeMap<String, Integer> map = new TreeMap<>();
map.put("b", 2);
map.put("a", 1);
System.out.println(map.firstKey()); // a

Leave a reply

Your email address will not be published. Required fields are marked *