Sort all the characters according to their brightness I wrote a little fractal noise generator the other day, and to test it I wanted to display the dark values with a darker character and the bright values with bright characters (I use a dark background with light foreground). So I wrote a simple java program to do this, and here it is:

package com.loovjo.brightSort;

import java.awt.Font;
import java.awt.Graphics;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.stream.Collectors;

public class Main {

    private static final int IMG_SIZE = 128;

    public static void main(String[] args) {
        ArrayList&lt;Character&gt; order = new ArrayList&lt;Character&gt;();

        HashMap&lt;Character, Float&gt; brightness = new HashMap&lt;Character, Float&gt;();

        long timer = System.currentTimeMillis();

        int max = 0xFF;

        for (char c = 0; c &lt; max; c++) {
            Character.UnicodeBlock block = Character.UnicodeBlock.of(c);
            if (!(!Character.isISOControl(c)) &amp;&amp; c != KeyEvent.CHAR_UNDEFINED &amp;&amp; block != null
                &amp;&amp; block != Character.UnicodeBlock.SPECIALS)
                // We don't want any unprintables in out gradient.
                continue;

            brightness.put(c, getBrightness(c));
            if (System.currentTimeMillis() - timer &gt; 100) {
                timer = System.currentTimeMillis();
                System.out.println(((float) c / max) * 100 + "% done.");
            }
        }

        // Sort brightness into order

        while (!brightness.isEmpty()) {
            char min = '\0';
            float val = Float.MAX_VALUE;
            for (Entry&lt;Character, Float&gt; e : brightness.entrySet()) {
                if (e.getValue() &lt; val) {
                    val = e.getValue();
                    min = e.getKey();
                }
            }
            brightness.remove(min);
            order.add(min);
        }
        for (int i = 0; i &lt; 10; i++)
            System.out.println(order.stream().map(c -&gt; "" + c).collect(Collectors.joining()));

     }

    private static float getBrightness(char c) {
        BufferedImage img = new BufferedImage(IMG_SIZE, IMG_SIZE, BufferedImage.TYPE_INT_RGB);
        Graphics g = img.getGraphics();
        g.setFont(new Font("Monaco", Font.PLAIN, (int) (img.getHeight() * 0.5)));
        // img.getHeight() * 0.5 because else some of the characters will be
        // rendered off-screen, giving them wierd values

        g.drawString(c + "", 0, g.getFont().getSize());
        g.dispose();

        int totalBrightness = 0;
        for (int x = 0; x &lt; img.getWidth(); x++) {
            for (int y = 0; y &lt; img.getHeight(); y++) {
                totalBrightness += img.getRGB(x, y) &amp; 0xFF;
            }
        }

        return totalBrightness / (float) (img.getWidth() * img.getHeight());
    }

}


For those of you who can't run this program, here's a screenshot of the output:
You may want to separate the logic to determine if a character is printable into a method and rewrite the brightness calculation using streams:

Map&lt;Character, Float&gt; brightness = IntStream.range(0, max)
        .mapToObj(x -&gt; (char) x)
        .filter(Main::isPrintable)
        .collect(toMap(c -&gt; c, Main::getBrightness));


Your sort algorithm is very inefficient, and there isn't a need to write your own.  Streams API makes it nice and clean:

List&lt;Character&gt; order = brightness.entrySet().stream()
        .sorted(comparingByValue())
        .map(Map.Entry::getKey)
        .collect(toList());


Above snippets assume static imports

import static java.util.Map.Entry.comparingByValue;
import static java.util.stream.Collectors.toList;
import static java.util.stream.Collectors.toMap;