Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
4th Edition
ISBN: 9780134787961
Author: Tony Gaddis, Godfrey Muganda
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 18, Problem 22TF
Program Description Answer
If the user iterates through a “HashSet”, the objects will not be retrieved in the same order, which they were added to the “HashSet”.
Hence, the given statement is “False”.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Write a method void removeShortStrings(HashSet<String> set). The method should remove from the set any string that is shorter than 100.
Duplicate Set
This function will receive a list of elements with duplicate elements. It should add all of the duplicate elements to a set and return the set containing the duplicate elements. A duplicate element is an element found more than one time in the specified list. The order of the set does not matter.
Signature:
public static HashSet<Object> duplicateSet(ArrayList<Object> list)
Example:
INPUT: [2, 4, 5, 3, 3, 5]
OUTPUT: {5, 3}
(Java) (data structure) write an entire generic hashing program with a custom hashcode function and a Test class all classes should be generic and the program should have these methods :
1. rehash (to rehash when the array is 0.75 full)
2. rehash insert ( to insert items from the old array to the new larger one)
3. put (to insert into the hashtable)
4.getAll(to get all the items on the table you should override toString)
5. delete (to delete an item from the table)
6. custom hashcode function for T type
Chapter 18 Solutions
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
Ch. 18.1 - Prob. 18.1CPCh. 18.1 - What are the three general types of collections?Ch. 18.1 - Prob. 18.3CPCh. 18.1 - Prob. 18.4CPCh. 18.1 - Prob. 18.5CPCh. 18.1 - Prob. 18.6CPCh. 18.1 - Prob. 18.7CPCh. 18.2 - Prob. 18.8CPCh. 18.2 - Prob. 18.9CPCh. 18.2 - Prob. 18.10CP
Ch. 18.2 - Prob. 18.11CPCh. 18.2 - Prob. 18.12CPCh. 18.2 - Prob. 18.13CPCh. 18.2 - Prob. 18.14CPCh. 18.2 - Prob. 18.16CPCh. 18.2 - Prob. 18.17CPCh. 18.2 - Prob. 18.18CPCh. 18.2 - Prob. 18.20CPCh. 18.3 - Prob. 18.21CPCh. 18.3 - Prob. 18.22CPCh. 18.3 - Prob. 18.23CPCh. 18.3 - Prob. 18.24CPCh. 18.3 - Any time you override the Object classs equals...Ch. 18.3 - Prob. 18.26CPCh. 18.3 - Prob. 18.27CPCh. 18.3 - Prob. 18.28CPCh. 18.4 - Prob. 18.29CPCh. 18.4 - Prob. 18.31CPCh. 18.4 - Prob. 18.32CPCh. 18.6 - How do you define a stream of elements?Ch. 18.6 - How does a stream intermediate operation differ...Ch. 18.6 - Prob. 18.35CPCh. 18.6 - Prob. 18.36CPCh. 18.6 - Prob. 18.37CPCh. 18.6 - Prob. 18.38CPCh. 18.6 - Prob. 18.39CPCh. 18 - Prob. 1MCCh. 18 - Prob. 2MCCh. 18 - This type of collection is optimized for...Ch. 18 - Prob. 4MCCh. 18 - A terminal operation in a stream pipeline is also...Ch. 18 - Prob. 6MCCh. 18 - Prob. 7MCCh. 18 - This List Iterator method replaces an existing...Ch. 18 - Prob. 9MCCh. 18 - Prob. 10MCCh. 18 - This is an object that can compare two other...Ch. 18 - This class provides numerous static methods that...Ch. 18 - Prob. 13MCCh. 18 - Prob. 14MCCh. 18 - Prob. 15TFCh. 18 - Prob. 16TFCh. 18 - Prob. 17TFCh. 18 - Prob. 18TFCh. 18 - Prob. 19TFCh. 18 - Prob. 20TFCh. 18 - Prob. 21TFCh. 18 - Prob. 22TFCh. 18 - Prob. 1FTECh. 18 - Prob. 2FTECh. 18 - Prob. 3FTECh. 18 - Prob. 4FTECh. 18 - Write a statement that declares a List reference...Ch. 18 - Prob. 2AWCh. 18 - Assume that it references a newly created iterator...Ch. 18 - Prob. 4AWCh. 18 - Prob. 2SACh. 18 - Prob. 4SACh. 18 - Prob. 5SACh. 18 - Prob. 6SACh. 18 - How does the Java compiler process an enhanced for...Ch. 18 - Prob. 8SACh. 18 - Prob. 9SACh. 18 - Prob. 10SACh. 18 - Prob. 11SACh. 18 - Prob. 12SACh. 18 - Prob. 13SACh. 18 - Prob. 14SACh. 18 - Word Set Write an application that reads a line of...Ch. 18 - Prob. 3PCCh. 18 - Prob. 5PCCh. 18 - Prob. 8PC
Knowledge Booster
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
- PLESE NO COPY PASTE Answer the following : (3 Marks) Create an ArrayList , HashMap and HashSet Add 2 elements/entries to ArrayList , HashMap and HashSet . ArrayList HashMap HashSetarrow_forwardC++ Complete the program that will allow the user to enter data on 10 Halloween costumes. The program will create Costume objects and then store the Costume objects in a Hash Table. The Costume ID will be the key and a pointer to the Costume object will be the value. You are given Lab7.cpp, HashEntry.h, and Costume.h and you should not have to make any changes to these files at all. You will need to write HashTable.h, which implements the HashTable class. This should NOT be a template class. Your HashTable class should resolve collisions by linear probing and should use the HashEntry class for the linkedlist nodes. Because we’re using probing, there is no removal function. This is okay for this application, since we want to keep a record of costumes that are no longer being kept in stock. ---GIVEN--- Lab.cpp #include <iostream> #include "HashTable.h" #include "Costume.h" using namespace std; int main() { int size; int key; Costume *newCostume; string name; float price;…arrow_forwardThe compareTo method. First you compare this.ticker which is a String, then if they are the same then you compare by the this.purchasePrice which is a double hashCode public int hashCode() The hashCode method using the Code-> Generate equals and hashCode with no changes Overrides: hashCode in class Object Returns: int Representing the hashCode compareTo public int compareTo(Stock another) The compareTo method not auto generated Compares first by ticker and if the tickers are the same secondarily compares by price Specified by: compareTo" in interface Comparable<stock> Parameters: another - the object to be compared. Returns: int Representing order Throws: IllegalArgumentException"- if another is null.arrow_forward
- ' make a hashmap ' import hashlib import sys def insert (hashmap, key, value): ' insert a key value pair into the hashmap ' hashmap[key] = value def remove (hashmap, key): ' remove a key value pair from the hashmap ' del hashmap[key] def search (hashmap, key): ' search for a key in the hashmap ' if key in hashmap: return hashmap[key] else: return None def print (hashmap): ' print the hashmap ' for key in hashmap: print (key, ":", hashmap[key]) 'end of print' def main (): 'make a menu that lets the user call the functions' hashmap = {} while True: print (""" Menu: 1. Insert 2. Remove 3. Search 4. Print 5. Quit """) choice = input ("Enter your choice: ") if choice == "1": key = input ("Enter the key: ") value = input ("Enter the value: ") insert (hashmap, key, value) elif choice == "2":…arrow_forwardDoes this return an empty object or null: HashMap metadata = [:]arrow_forwardcode: public class PasswordGeneratorAndStorage {/*** Adds an application to the applications ArrayList. If index is -1, add application* to the end of applications. Else is index is within the size of applications, add* application at that index in applications. Otherwise, return. However, if applications * or application is null, return.* * @param applications* @param application* @param index*/public static void addApplication(ArrayList<String> applications, String application, int index) {// TODO: FILL IN BODY}/*** Generates a random password of length passwordLength and adds it to the end of* passwords if index is -1, or adds it to the index of passwords if index is within the* size of passwords (similar to how the addApplication adds an application). To generate* the random password, use rand to generate a random int within the size of characters. You* can then use this int to grab the char at that index in characters and concatenate that* to your String password variable.…arrow_forward
- What causes a collision? The program you are running crashes Two hash keys are the same The program is out of memory Many hash keys are in the arrayarrow_forwardGetting more errors please free. import java.util.HashMap;import java.util.Set;public class MapUse{ //main driver code public static void main(String[] args) { HashMap<String, Integer> map = new HashMap<>(); //insert map.put("abc", 1); map.put("def", 2); map.put("abc1", 10); map.put("def1", 20); map.put("abc", 5); //updates abc from 1 to 5, every key is unique, no dupplicate keys //check size System.out.println("size "+ map.size()); //check Presence if(map.containsKey("abc")){ System.out.println("has abc"); } if(map.containsKey("abc1")){ System.out.println("has abc1"); } //get Value int v = 0; if(map.containsKey("abc1")){ //checks whether the key is actually present v = map.get("abc1"); //to protect from null pointer exception } System.out.println(v); //remove int s = map.remove("abc"); //removes the…arrow_forwardUse C++ Programming language. The header file below defines a class for a simple hash table: hashMap.h Download hashMap.h Write a driver program to test the class with the following data: (520, "3100 Main St, Houston TX "); (37, "2200 Hayes Rd, Austin TX"); (226, "1775 West Airport St, San Antonio TX"); (273, "3322 Walnut Bend, Houston TX"); (491, "5778 Alabama, Waco TX"); (94, "3333 New St, Paris TX"); Make sure to test the find function for exiting and non-existing data 2. Modify the type of member key in class HashEntry from int to a string (this is useful is the key is e.g. the phone number or e-mail address). Use the string hash function discussed in class (see ppt notes) or search online for alternative functions that work on strings. 3. Modify the collision strategy of class HashMap to do separate chaining instead of linear probing. Be sure to modify the display function so that items in the bucket chains are also displayed in a pre-defined order…arrow_forward
- JAVA PROGRAMMING 1. Create a folder named LastName_FirstName in your local drive. (ex. Reyes_Mark) 2. Using NetBeans, create a Java project named BirthMonth. Set the project location to your ownfolder. 3. Import Scanner, Set, HashSet, and Collections from the java.util package. 4. Create empty hash sets named group1, group2, and self. 5. The output shall: Ask six (6) of your classmates to enter their birth month. The first three (3) values shall be addedto the group1 set and the remaining to group2. Display the values entered by each group. Ask you to type your birth month, which is to be stored to the set named self. Show the union, intersection, and difference based on the two (2) groups. Display a message to tell whether you have the same birth month with any of your classmates.arrow_forwardIn this problem you are given a Set of data and an element. You will need to look to see if the set contains the element. If found return the element otherwise return "?". "Note sometimes the names of classes/variables/objects can be misleading!!!!" import java.util.HashSet;public class SetContainsLetter{public static Object solution(HashSet<Integer> nums, int elm){// ↓↓↓↓ your code goes here ↓↓↓↓return null;}}arrow_forwardTwo elements with identical keys should have the same hash code. Group of answer choices True Falsearrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education