Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] argv) throws Exception {
        Map<String, List<String>> fontFaceNames = new HashMap<String, List<String>>();
        GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
        Font[] fonts = ge.getAllFonts();

        for (int i = 0; i < fonts.length; i++) {
            String familyName = fonts[i].getFamily();
            String faceName = fonts[i].getName();

            List<String> list = fontFaceNames.get(familyName);
            if (list == null) {
                list = new ArrayList<String>();
                fontFaceNames.put(familyName, list);
            }
            list.add(faceName);
        }
        System.out.println(fontFaceNames);

    }
}