Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class HappyBirthday {
    public static void main(String[] args) {
        List<String> list = new ArrayList<String>();
        Set<String> set = new TreeSet<String>();
        Map<String, String> map = new TreeMap<String, String>();
        String s = "HappyBirthday";
        int length = s.length();
        for (int i = 0; i < length; i++) {
            String c = s.charAt(i) + "";
            String o = s.charAt(length - i) + "";
            list.add(c);
            set.add(c);
            map.put(c, o);
        }
        System.out.println(list + "\n" + set + "\n" + map);
    }
}


[H, a, p, p, y, B, i, r, t, h, d, a, y]
[d, t, r, B, p, a, H, h, y, i]
{B=r, H=y, a=a, d=p, h=p, i=i, p=h, r=B, t=y, y=H}
[y, a, d, h, t, r, i, B, y, p, p, a, H]
[d, t, r, B, p, a, H, h, y, i]
{d=p, t=y, r=B, B=r, p=h, a=a, H=y, h=p, y=H, i=i}
[H, a, p, p, y, B, i, r, t, h, d, a, y]
[B, H, a, d, h, i, p, r, t, y]
{B=r, H=y, a=a, d=p, h=p, i=i, p=h, r=B, t=y, y=H}
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: TreeMap In Java - java.util.TreeMap

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App