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
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
using System; class Program { publicstaticvoid Main(string[] args) { int number = 1,i; while (number <= 88) { Console.WriteLine(number); number = number + 2; { Random r = new Random(); int[] randNo=newint[3]; for(i=0;i<3;i++) { randNo[i]= r.Next(1,88) Console.WriteLine("Random Number between 1 and 88 is "+randNo); } } } } }     how can this program be fixed to choose three random numbers in C# between 1-88 instead of just one random number?
public class Test { } public static void main(String[] args) { String str = "Salom"; System.out.println(str.indexOf('t)); }
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