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 1MC
Program Description Answer
List is used to store the elements in an ordered sequence and it allows duplicate elements.
Hence, the correct answer is option “A”.
Expert Solution & Answer
Explanation of Solution
List:
- List is an ordered collection, which is used to order their elements by its position.
- It allows duplicate elements.
- New methods are defined inside the List interface.
- Using “ListIterator”, a list can be inserted in both forward and backward direction.
- It allows any number of null values in its collection.
Explanation for incorrect options:
b. Set:
Set is a data structure that is used for storing and processing non duplicate elements.
Hence, the option “B” is wrong.
c. Map:
Map is an interface which contains values on the basis of key and a value pair and represents a mapping between them.
Hence, the option “C” is wrong.
d.Hash set:
Hash set is used to create a collection that uses a hash table for storage.
Hence, the option “D” is wrong.
Want to see more full solutions like this?
Subscribe now to access step-by-step solutions to millions of textbook problems written by subject matter experts!
Students have asked these similar questions
Apart from the main list in the list above, elements with the same value are also linked. According to this;
a) Write the Generic Node class.
b) Write the method that adds a new element to the end of the list.
JAVA CODE
MyArrayList is defined inListing24.2. Write a program that generates 1000000 random double valuesbetween 0 and 999999 and stores them in a MyArrayList and in a MyHashSet.Generate a list of 1000000 random double values between 0 and 1999999. Foreach number in the list, test if it is in the array list and in the hash set. Run yourprogram to display the total test time for the array list and for the hash set.
TRUE OR FALSE
Can we use a foreach loop to traverse the elements in any instance of the Collection object?
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
- Apart from the main list in the list above, elements with the same value are also linked. According to this; a) Write the Generic Node class. b) Write the method that adds a new element to the end of the list.arrow_forwardIf N represents the number of elements in the collection, then the contains method of the ArrayCollection class is O(1). True or False If N represents the number of elements in the list, then the index-based add method of the ABList class is O(N). True or Falsearrow_forwardRemoves the element with key k if it exists. The position of current is// unspecified after calling this method.The first element of the returned pair // indicates whether k was removed, and the second is the number of key// comparisons made.Pair<Boolean, Integer> remove(K key); // Returns all keys of the map as a list sorted in increasing order. List<K> getAll(); } write this method javaarrow_forward
- Create code that will find duplicate keys in a linked list and remove them all.arrow_forwardWhat does the following function do for a given Linked List? void fun1(struct node* head){if(head == NULL)return;fun1(head->next);printf("%d ", head->data);}arrow_forward2. Using the Hashtable class, write a spelling checker program that readsthrough a text file and checks for spelling errors. You will, of course, haveto limit your dictionary to several common words.3. Create a new Hash class that uses an arraylist instead of an array for thehash table. Test your implementation by rewriting (yet again) the computerterms glossary application.arrow_forward
- 9.5 Write a method of SinglyLinkedList, called reverse, that reverses theorder of the elements in the list. This method should be destructive—it shouldmodify the list upon which it acts.9.6 Write a method of DoublyLinkedList, called reverse, that reverses theorder of the elements in the list. This method should be destructive.9.7 Write a method of CircularList, called reverse, that reverses theorder of the element in the list. This method should be destructive.9.8 Each of the n references in a singly linked list are needed if we wishto remove the final element. In a doubly linked list, are each of the additional n previous references necessary if we want to remove the tail of thelist in constant time? (Hint: What would happen if we mixed Nodes andDoublyLinkedNodes?)arrow_forwardFor the following code, indicate the weighted edge values. List<WeightedEdge> list = new ArrayList<>();list.add(new WeightedEdge(1, 2, 3.5));list.add(new WeightedEdge(2, 3, 4.5));WeightedEdge e = java.util.Collections.max(list);e.u = e.v = e.weight =arrow_forwardIf operations given below is applied on a stack, what will be the result? For array implementation we need is_full() operation, however in linked list case this function is not required. Explain the reason createStack()push(1)push(2)push(1)peek()push(2)pop()pop()pop()push(2)push(1)push(2)arrow_forward
- 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}arrow_forwardread carefully please Without using the java collections interface (i.e. do not import java.util.List, LinkedList, etc. ) I need to write a java program that inserts a new String element (String newItem) into a linked list after another specified item (String itemToInsertAfter). For example if items "A", "B", "C" and "D" are in a linked list in that order and the below method is called, insertAfter("E", "C"), then "E" would be inserted after "C", making the final list to be "A", "B", "C", "E" and "D" with no nulls or blank elements or any elements missing or anything. It should work for all lenghths of linkedlists of Strings. I am not sure how to do this simple problem, can you help? public Boolean insertAfter(String newItem, String itemToInsertAfter) { // returns true if done successfully, else returns false if itemToInsertAfter cannot be found or some other error }arrow_forwardGiven main() in the ShoppingList class, define an insertAtEnd() method in the ItemNode class that adds an element to the end of a linked list. DO NOT print the dummy head node. Ex. if the input is: 4 Kale Lettuce Carrots Peanuts where 4 is the number of items to be inserted; Kale, Lettuce, Carrots, Peanuts are the names of the items to be added at the end of the list. The output is: Kale Lettuce Carrots Peanuts public class ItemNode { private String item; private ItemNode nextNodeRef; // Reference to the next node public ItemNode() { item = ""; nextNodeRef = null; } // Constructor public ItemNode(String itemInit) { this.item = itemInit; this.nextNodeRef = null; } // Constructor public ItemNode(String itemInit, ItemNode nextLoc) {…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