Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.HashMap;
import java.util.Map;

public class Main {
    public static void main(String[] args) {
        Map<Character, Integer> counting = new HashMap<Character, Integer>();
        String testcase1 = "this is a test";
        for (char ch : testcase1.toCharArray()) {
            Integer freq = counting.get(ch);
            counting.put(ch, (freq == null) ? 1 : freq + 1);
        }
        System.out.println(counting.size() + " distinct characters:");
        System.out.println(counting);
    }

}