Menu
Question Index
...

What will be the output of the following program?

import java.util.*;

public class PrintStatment11 {
    public void findDuplicateChars(String str) {
        Map<Character, Integer> dupMap = new HashMap<Character, Integer>();
        char[] chrs = str.toCharArray();
        for (Character ch : chrs) {
            if (dupMap.containsKey(ch)) {
                dupMap.put(ch, dupMap.get(ch) + 1);
            } else {
                dupMap.put(ch, 1);
            }
        }
        Set<Character> keys = dupMap.keySet();
        for (Character ch : keys) {
            if (dupMap.get(ch) > 1)
                System.out.println(ch + "--->" + dupMap.get(ch));
        }
    }
    public static void main(String a[]) {
        PrintStatment11 statmt = new PrintStatment11();
        statmt.findDuplicateChars("java programming");
    }
}


g--->2
r--->2
a--->3
m--->2
g--->3
r--->2
a--->3
m--->3
g--->1
r--->1
a--->1
m--->1
g--->2
r--->2
a--->3
b--->2
Compilation Error or Runtime Error

Doubts

Problems

Topic: Java HashMap Implementation

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App