Introduction to Java Programming and Data Structures, Comprehensive Version, Student Value Edition (11th Edition)
bartleby

Concept explainers

Question
Book Icon
Chapter 21.5, Problem 21.5.3CP
Program Plan Intro

Program:

//import the util package

import java.util.*;

//class Definition

public class Test {

// main method

public static void main(String[] args) {

//declare a LinkedHashMap

Map<Integer, String> map = new LinkedHashMap<>();

//insert keys and values into the map

map.put("123", "John Smith");

map.put("111", "George Smith");

map.put("123", "Steve Yao");

map.put("222", "Steve Yao");

//print elements present in the map

System.out.println("(1) " + map);

/*print elements in a new Treemap which implements map */

System.out.println("(2) " + new TreeMap<, String>(map));

//check if key equals 123 then print the value

map.forEach((k, v) -> {

if (k.equals("123"))

System.out.println(v);});

}

}

Blurred answer
Students have asked these similar questions
Show all the work
Construct a frequency polygon density estimate for the sample in Question 1, using bin width determined by Sturges’ Rule.
Show all the work
Knowledge Booster
Background pattern image
Computer Science
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT
Text book image
Microsoft Visual C#
Computer Science
ISBN:9781337102100
Author:Joyce, Farrell.
Publisher:Cengage Learning,
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
Text book image
Programming Logic & Design Comprehensive
Computer Science
ISBN:9781337669405
Author:FARRELL
Publisher:Cengage
Text book image
CMPTR
Computer Science
ISBN:9781337681872
Author:PINARD
Publisher:Cengage
Text book image
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781305480537
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT