Get all Available Charsets in Java

The following java code can be useful to get all the available charset on the system.

import java.nio.charset.Charset;
import java.util.Iterator;
import java.util.Set;
import java.util.SortedMap;

public class CharsetEncoding {

        public static void main(String[] args) {
                SortedMap m = Charset.availableCharsets();
                Set k = m.keySet();
                System.out.println("Canonical name, Display name,"
                                +" Can encode, Aliases");
                Iterator i = k.iterator();
                while (i.hasNext()) {
                        String n = (String);
                        Charset e = (Charset) m.get(n);
                        String d = e.displayName();
                        boolean c = e.canEncode();
                        System.out.print(n+", "+d+", "+c);
                        Set s = e.aliases();
                        Iterator j = s.iterator();
                        while (j.hasNext()) {
                                String a = (String);
                                System.out.print(", "+a);

If you want to learn more retro games news, read our magazine and subscribe to our newsletter.