Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.HashMap;

public class Main {

    public static void main(String[] args) {
        HashMap<Character, Integer> map = new HashMap<Character, Integer>();
        String test = "BUNANA";
        char[] chars = test.toCharArray();

        for (int i = 0; i < chars.length; i++) {
            if (!map.containsKey(chars[i])) {
                map.put(chars[i], 1);
            }
            map.put(chars[i], map.get(chars[i]) + 1);
        }

        System.out.println(map.toString());
    }

}