Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.Map;
import java.util.TreeMap;

public class Main {
    public static void main(String[] args) {
        String yourString = "UNDERSTAND";
        Map<Character, Integer> count = new TreeMap<Character, Integer>();
        for (char c : yourString.toCharArray()) {
            if (count.containsKey(c)) {
                count.put(c, (int) count.get(c) + 1);
            } else {
                count.put(c, 1);
            }
        }
        System.out.println(count);
    }
}