Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
bartleby

Concept explainers

Question
Book Icon
Chapter 21.2, Problem 21.2.7CP
Program Plan Intro

Program:

//import util package

import java.util.*;

//class definition

public class Test {

// main method

public static void main(String[] args) {

//Create a new Set set1 ofLinkedHash Set type

LinkedHashSet<String> set1 = new LinkedHashSet<>();

/* add NewYork element into the set using the add() method */

set1.add("New York");

/*Create a new set set2 which equals set1 */

LinkedHashSet<String> set2 = set1;

//clone set1 and assign it a new set set2

LinkedHashSet<String> set3 =

(LinkedHashSet<String>)(set1.clone());

//add Atlanta to the set1

set1.add("Atlanta");

//print each set

System.out.println("set1 is " + set1);

System.out.println("set2 is " + set2);

System.out.println("set3 is " + set3);

/* Print each element present in set 1 using the ForEach() method */

set1.forEach(e -> System.out.print(e + " "));

}

}

Blurred answer
Students have asked these similar questions
public static void main(String[] args) { int a; int b; int c; c = quad(0,1, 2); b = quad(1, 2, 3); a = quad(5, 6, 7); c = c +b+ a; } private static int quad(int a, int b, int c) { int r; r= a +b+ c; return r; } For the code above, how many entries does the activation record for method quad have? During the execution of main, at most how many activation records are existent on the run-time stack?
Java output caffeine levels
Question 37 public static void main(String[] args) { Dog[] dogs = { new Dog(), new Dog()}; for(int i = 0; i >>"+decision()); } class Counter { private static int count; public static void inc() { count++;} public static int getCount() {return count;} } class Dog extends Counter{ public Dog(){} public void wo(){inc();} } class Cat extends Counter{ public Cat(){} public void me(){inc();} } The Correct answer: Nothing is output O 2 woofs and 5 mews O 2 woofs and 3 mews O 5 woofs and 5 mews O
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
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education