Menu
Question Index
...

What will be the output of the following program?

import java.util.LinkedHashMap;

public class SwimmingStyles {
    public static void main(String[] args) {
        CustomMap cm = new CustomMap();
        cm.put("back", "stroke");
        System.out.print(cm);
        cm.put("front", "crawl");
        System.out.println(cm);
        cm.put("breast", "stroke");
        System.out.print(cm);
        cm.put("butterfly", "stroke");
        System.out.println(cm);
    }
}

class CustomMap extends LinkedHashMap<String, String> {
    private static final long serialVersionUID = 8169641341001802000L;
    protected boolean removeEldestEntry(java.util.Map.Entry<String, String> eldest) {
        return size() > 3 || eldest.getValue().contains("stroke");
    }
}


{back=stroke}{back=stroke, front=crawl}
{back=stroke, front=crawl, breast=stroke}{front=crawl, breast=stroke, butterfly=stroke}
{}{front=crawl}
{front=crawl, breast=stroke}{front=crawl, breast=stroke, butterfly=stroke}
{back=stroke}{back=stroke, front=crawl}
{back=stroke, front=crawl, breast=stroke}{back=stroke, front=crawl, breast=stroke, butterfly=stroke}
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: LinkedHashMap In Java with Code Example

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App