entry

How to sort data that’s in a Java HashMap (using a TreeMap)

Here’s a brief example of how to sort data that’s already in a Java HashMap. First, some HashMap data:

import java.util.*;

Map<Integer, Float> playMap = new HashMap<Integer, Float>() {{
    put(10,  1f);
    put(12,  2f);
    put(15,  4f);
    put(18,  6f);
    put(20,  6f);
    put(25,  7f);
    put(30,  6f);
    put(35,  5f);
    put(40,  5f);
}};

A HashMap won’t keep that data in sorted order, so if you want your data sorted, one way to sort it is to add the elements to a Java TreeMap:

A Java JFreeChart x/y plot/chart/graph example

In an effort to share some source code (but without taking the time to explain it), here’s some Java source code that I just used to create a JFreeChart chart/graph of some data that I use in my Android football game:

Java/Swing UIManager default values

As I'm preparing a different Java Swing tutorial, I thought I'd share a test class I just created to look at the default entries from the Java UIManager class.

Here's the source code for my Java class that prints all the Java Entry objects from the UIManager class. As you can see, I call the getLookAndFeelDefaults method of that class, and then call the entrySet method of that class to get all the default entries: