Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
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
Suppose your computer is responding very slowly to information requests from the Internet. You observe that your network gateway shows high levels of network activity even though you have closed your e-mail client, Web browser, and all other programs that access the Internet. What types of malwares could cause such symptoms? What steps can you take to check whether malware has gained access to your system? What tools can you use at each step? If you identify malware, what ways might it have entered your system? How can you restore your PC to safe operation, including the special software tools you may use?
R language
Using R language
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
New Perspectives on HTML5, CSS3, and JavaScript
Computer Science
ISBN:9781305503922
Author:Patrick M. Carey
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
C++ for Engineers and Scientists
Computer Science
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Course Technology Ptr