Java and TreeMap เป็น Collectionที่ใช้จัดเก็บข้อมูลในรูปแบบของ Key และ Value โดบ Collection ของ TreeMap ไม่อนุญาติใช้เก็บข้อมูลที่ซ้ำกันได้ถ้า Add ข้อมูลลงไปมันจะทับตัวเดิม และลำดับของข้อมูลจะให้ความสำคัญกับลำดับของข้อมูล และมีการจัดเรียงข้อมูลจาก Key ให้อัตโนมัติ 
 
Example 
 
package com.java.myapp;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.TreeMap;
public class MyClass {
	public static void main(String[] args) {
	   
		 TreeMap<String, String> tree = new TreeMap<String, String>();
		 
		 tree.put("Tel", "0819876107");
		 tree.put("MemberID", "1");
		 tree.put("Name", "Weerachai");
		 tree.put("Tel", "0819876107");
		 tree.put("Tel", "0819876107");
		  
		 Set<Entry<String, String>> set = tree.entrySet();
	      Iterator<Entry<String, String>> it = set.iterator();
	      while (it.hasNext()) {
	    	  Map.Entry me = (Map.Entry)it.next();
	          System.out.print("Key = " + me.getKey() + " , ");
	          System.out.println("Value = " + me.getValue());
	      }	     
		
	}
	
}
 
 
Output 
Key = MemberID , Value = 1 
Key = Name , Value = Weerachai 
Key = Tel , Value = 0819876107               
  
              			
			  
								  
			  
  
                          
  |