Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
11th Edition
ISBN: 9780134670942
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Question
Chapter 21.7, Problem 21.7.1CP
Program Plan Intro
Program:
//import util package
import java.util.*;
//class definition
public class Example_1
{
//main method
public static void main(String[] args)
{
/* declare singleton set and add "Chicago" */
Set<String>set = Collections.singleton("Chicago");
//add Dallas into set
set.add("Dallas");
//print set
System.out.println("set is " + set);
}
}
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Set are ordered but not indexed
True or false.
Does a set allow you to store duplicate elements?
What will happen if a set has duplicate entries? python
the duplicate copies will not be affected
the duplicate copies will still be printed
none
the duplicate copies will be ignored
Chapter 21 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Ch. 21.2 - Prob. 21.2.1CPCh. 21.2 - Prob. 21.2.2CPCh. 21.2 - Prob. 21.2.3CPCh. 21.2 - Prob. 21.2.4CPCh. 21.2 - Prob. 21.2.5CPCh. 21.2 - Suppose set1 is a set that contains the strings...Ch. 21.2 - Prob. 21.2.7CPCh. 21.2 - Prob. 21.2.8CPCh. 21.2 - What will the output be if lines 67 in Listing...Ch. 21.2 - Prob. 21.2.10CP
Ch. 21.3 - Prob. 21.3.1CPCh. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores...Ch. 21.3 - Suppose you need to write a program that stores a...Ch. 21.3 - Prob. 21.3.5CPCh. 21.3 - Prob. 21.3.6CPCh. 21.4 - Prob. 21.4.1CPCh. 21.4 - Prob. 21.4.2CPCh. 21.5 - Prob. 21.5.1CPCh. 21.5 - Prob. 21.5.2CPCh. 21.5 - Prob. 21.5.3CPCh. 21.6 - Prob. 21.6.1CPCh. 21.6 - Prob. 21.6.2CPCh. 21.6 - Prob. 21.6.3CPCh. 21.6 - Prob. 21.6.4CPCh. 21.7 - Prob. 21.7.1CPCh. 21.7 - Prob. 21.7.2CPCh. 21 - Prob. 21.1PECh. 21 - (Display nonduplicate words in ascending order)...Ch. 21 - Prob. 21.3PECh. 21 - (Count consonants and vowels) Write a program that...Ch. 21 - Prob. 21.6PECh. 21 - (Revise Listing 21.9, CountOccurrenceOfWords.java)...Ch. 21 - Prob. 21.8PECh. 21 - Prob. 21.9PE
Knowledge Booster
Similar questions
- (6) Write out the POWER SET. Keep in mind a subset can be made of any combination of elements appearing in the original set (provided it’s a UNIQUE combination).{2,4,8}arrow_forward6.2 Create a Product class with Product Id & Product Name. Write a program to accept information of 10 products and store that in HashSet. Do following operations, a.Search a particular product in the HashSet.b.Remove a particular product from the HashSet by using product id.(Referbelow table for the product list) Product Id Product Name P001 Maruti 800 P002 Maruti Zen P003 Maruti Dezire P004 Maruti Altoarrow_forward22. What is the difference between the set and multiset STL classes in Chapter 3? Group of answer choices The multiset class allows duplicate values in the container, whereas the set class requires unique values. The multiset class allows unique values in the container, whereas the set class requires duplicate values . The multiset class allows duplicate and unique values in the container, whereas the set class requires duplicate values. The multiset class allows duplicate values in the container, whereas the set class requires unique and duplicate values. They are using different name but identical .arrow_forward
- Are the elements of a set ordered or unordered?arrow_forwardSets store their elements in an unordered fashion.True or Falsearrow_forwardcan you fix this code #include <iostream>#include <list>using namespace std; class Hash{ int BIB; list<int>* tableSize;public: Hash(int V); // Constructor // inserts a key into hash table void insertItem(int x); // deletes a key from hash table void deleteItem(int key); // hash function to map values to key int hashFunction(int x) { return (x % BIB); } void displayHash();}; Hash::Hash(int b){ this->BIB = b; tableSize = new list<int>[BIB];} void Hash::insertItem(int key){ int index = hashFunction(key); tableSize[index].push_back(key);} void Hash::deleteItem(int key){ // get the hash index of key int index = hashFunction(key); // find the key in (index)th list list <int> ::iterator i; for (i = tableSize[index].begin(); i != tableSize[index].end(); i++) { if (*i == key) break; } // remove key if it is found in hash table, if (i != tableSize[index].end())…arrow_forward
- def get_legal_word_scores(letters, dictionary, value_dict): """ Given a str of letters that we can use, and a dictionary that contains all legal words allowed in scrabble game, and a value_dict that maps each letter to a score, Returns a dictionary that contains all possible scores earned by any legal word as the key, and for each score, the score/key maps to a list of words that are from the dictionary made from the given letters and computes to that score. The list should be in alphabetical order. """arrow_forwardExpress the following set using the roster method. Express the elements as strings, not n-tuples. 1. {xy: x ∈ {aa, ab} and y ∈ {a} ∪ {a}2}arrow_forwardPYTHON: Please fix my code to print the correct traversals, especially at the def functions, because I could not print the correct results of the inorder, postorder, and preorder traversals from the user input. #POSTORDERclass Node: def __init__(self, data): self.left = None self.right = None self.data = data # Insert Node def insert(self, data): if self.data: if data < self.data: if self.left is None: self.left = Node(data) else: self.left.insert(data) elif data > self.data: if self.right is None: self.right = Node(data) else: self.right.insert(data) else: self.data = data # Print the Tree def PrintTree(self): if self.left: self.left.PrintTree() print(self.data),…arrow_forward
- 1)For a given set s, which method returns True if item is in s, or False otherwise. a. s.__iter__(item) b. s.__contains__(item) c. s = set() d. S1.__sub__(s2) 2)In AbstractSet class, which method returns the union of two sets? a. __union__ b. __and__ c. __sub__ d. __or__arrow_forwardWrite a code that contains a tuple of first name and another set contains a list of the last name, then concatenate the index of tuple A with the index of list B. Example: x= ("Ibrahim", "Foad") y = ["Adeshola", "Fortune"] Output: Ibrahim Adeshola Foad Fortunearrow_forwardHow could this code work with... lists instead of dictionaries? without the items as in... def Find_average(heights_dict): for city, heights in heights_dict.items(): average = sum(heights) / len(heights) print(f"{city}: {average}") import csv csv_data = []with open("C:\\Users\\lucas\\Downloads\\sample-data.csv") as f: reader = csv.reader(f) for row in csv.reader(f): csv_data .append(list(row)) f.close()csv_data.pop(0) difference_list = [] def Sorting_cities(data): cities = [] for i in range(len(data)): cities.append(data[i][1]) cities.sort() return cities city_list = Sorting_cities(csv_data)print(city_list) def Listing_cities(cities): single_cities = [] for city in cities: if city not in single_cities: single_cities.append(city) return single_cities unique_cities = Listing_cities(city_list)print(unique_cities) def Counting_cities_and_people(single_cities, cities): people_count = [] for city in…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage Learning
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning