Skip to content

Instantly share code, notes, and snippets.

@megascus
Created October 16, 2012 14:55
Show Gist options
  • Save megascus/3899786 to your computer and use it in GitHub Desktop.
Save megascus/3899786 to your computer and use it in GitHub Desktop.
使用出来る文字コード一覧
public class CharSetMain {
public static void main(String[] args) {
for (Charset cs : Charset.availableCharsets().values()) {
System.out.println(charsetToString(cs));
}
}
private static String charsetToString(Charset cs) {
return cs.name() + aliasesToString(cs);
}
private static String aliasesToString(Charset cs) {
Set<String> aliases =cs.aliases();
if (aliases.isEmpty()) {
return "[]";
}
StringBuilder b = new StringBuilder();
b.append("[");
for (String name : aliases) {
b.append(name);
b.append(", ");
}
b.delete(b.length() - 2, b.length());
b.append("]");
return b.toString();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment