Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
11th Edition
ISBN: 9780134671710
Author: Y. Daniel Liang
Publisher: PEARSON
expand_more
expand_more
format_list_bulleted
Concept explainers
Expert Solution & Answer
Chapter 20.7, Problem 20.7.5CP
Explanation of Solution
binary() method for ArrayList or LinkedList:
The Collections.binary(list, key) is used to do the binary search for ArrayList or LinkedList. This method used to search the list based on the key.
The Syntax is given below:
Collections.binary(list, key);
For Example:
LinkedList<String> l = new LinkedList<>();
l.add("C");
l.add("Python");
l.add("Java");
Colections.binary(l, "Python");
Explanation:
- Create an object for LinkedList for “l” and add the values into list such as C, Python, and Java. Then, to search the list based on the key “Python” the following statement is used:
Collections.binary(l, "Python")
- The above statement search the list based on key and gives the result as 1.
Therefore, “Collections...
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
If 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 False
What is the ArrayList list's starting size?
In which scenarios would you prefer to use an array over a linked list, and vice versa?
Chapter 20 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global Edition)
Ch. 20.2 - Prob. 20.2.1CPCh. 20.2 - Prob. 20.2.2CPCh. 20.2 - Prob. 20.2.3CPCh. 20.2 - Prob. 20.2.4CPCh. 20.2 - Prob. 20.2.5CPCh. 20.3 - Prob. 20.3.1CPCh. 20.3 - Prob. 20.3.2CPCh. 20.3 - Prob. 20.3.3CPCh. 20.3 - Prob. 20.3.4CPCh. 20.4 - Prob. 20.4.1CP
Ch. 20.4 - Prob. 20.4.2CPCh. 20.5 - Prob. 20.5.1CPCh. 20.5 - Suppose list1 is a list that contains the strings...Ch. 20.5 - Prob. 20.5.3CPCh. 20.5 - Prob. 20.5.4CPCh. 20.5 - Prob. 20.5.5CPCh. 20.6 - Prob. 20.6.1CPCh. 20.6 - Prob. 20.6.2CPCh. 20.6 - Write a lambda expression to create a comparator...Ch. 20.6 - Prob. 20.6.4CPCh. 20.6 - Write a statement that sorts an array of Point2D...Ch. 20.6 - Write a statement that sorts an ArrayList of...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.6 - Write a statement that sorts a two-dimensional...Ch. 20.7 - Are all the methods in the Collections class...Ch. 20.7 - Prob. 20.7.2CPCh. 20.7 - Show the output of the following code: import...Ch. 20.7 - Prob. 20.7.4CPCh. 20.7 - Prob. 20.7.5CPCh. 20.7 - Prob. 20.7.6CPCh. 20.8 - Prob. 20.8.1CPCh. 20.8 - Prob. 20.8.2CPCh. 20.8 - Prob. 20.8.3CPCh. 20.9 - How do you create an instance of Vector? How do...Ch. 20.9 - How do you create an instance of Stack? How do you...Ch. 20.9 - Prob. 20.9.3CPCh. 20.10 - Prob. 20.10.1CPCh. 20.10 - Prob. 20.10.2CPCh. 20.10 - Prob. 20.10.3CPCh. 20.11 - Can the EvaluateExpression program evaluate the...Ch. 20.11 - Prob. 20.11.2CPCh. 20.11 - If you enter an expression "4 + 5 5 5", the...Ch. 20 - (Display words in ascending alphabetical order)...Ch. 20 - (Store numbers in a linked list) Write a program...Ch. 20 - (Guessing the capitals) Rewrite Programming...Ch. 20 - (Sort points in a plane) Write a program that...Ch. 20 - (Combine colliding bouncing balls) The example in...Ch. 20 - (Game: lottery) Revise Programming Exercise 3.15...Ch. 20 - Prob. 20.9PECh. 20 - Prob. 20.10PECh. 20 - (Match grouping symbols) A Java program contains...Ch. 20 - Prob. 20.12PECh. 20 - Prob. 20.14PECh. 20 - Prob. 20.16PECh. 20 - (Directory size) Listing 18.10,...Ch. 20 - Prob. 20.20PECh. 20 - (Nonrecursive Tower of Hanoi) Implement the...Ch. 20 - Evaluate expression Modify Listing 20.12,...
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
- not sure how to do this problem output doesnt matterarrow_forwardWhat is the difference between ArrayLists and arrays?arrow_forwardJava (Inserting Elements in a LinkedLists) Write a program that inserts 100 random integers from 1 to 100 in order into a Java LinkedList object. The program should sort the elements, then calculate the sum of the elements and the floating-point average of the elements.arrow_forward
- Question 44 Computer Science A list of elements has a size of 100. Choose the operations where an ArrayList would be faster than a LinkedList. (Select all that apply) Question 5 options: removing from index 99 inserting at index 1 removing from index 4 inserting at index 4 Full explain this question and text typing work onlyarrow_forward| Which data structure to use? Suppose you need to store a list of elements, if the number of elements in the program is fixed, what data structure should you use? (array, ArrayList, or LinkedList) If you have to add or delete the elements at the beginning of a list, should you use ArrayList or LinkedList? If most of operations on a list involve retrieving an element at a given index, should you use ArrayList or LinkedList?arrow_forwardJava language Write a method to insert an array of elements at index in a single linked list and then display this list. The method receives this array by parametersarrow_forward
- You will reverse your student ID by the linked list of Struct in C!!!! Input: 1->2->3->4->5->NULL Output: 5->4->3->2->1->NULL Create a linked list and insert your student ID elementwise to the list. Reverse the linked list and printout the result. Hint: You can use additional pointers to reverse the linked list. You can also use a stack and then simply assign the element to the stack and it will be reversed. Linked list, Stack, Queue example source code is available on week 7 resources section.arrow_forwarddata structures in javaarrow_forwardWhat criteria should be used to evaluate an ArrayList's performance?arrow_forward
- java program java method: Write a method replace to be included in the class KWLinkedList (for doubly linked list) that accepts two parameters, searchItem and repItem of type E. The method searches for searchItem in the doubly linked list, if found then replace it with repItem and return true. If the searchItem is not found in the doubly linked list, then insert repItem at the end of the linked list and return false. Assume that the list is not empty. You can use ListIterator and its methods to search the searchItem in the list and replace it with repItem if found. Do not call any method of class KWLinkedList to add a new node at the end of the list. Method Heading: public boolean replace(E searchItem, E repItem) Example: searchItem: 15 repItem: 17 List (before method call): 9 10 15 20 4 5 6 List (after method call) : 9 10 17 20 4 5 6arrow_forwardThe method: int indexOf(E target) of SingleLinkedList Class (A) Searches for target and returns the position of the last occurrence, or null if it is not in the List B Searches for target and returns the position of the first occurrence, or -1 if it is not in the List Searches for target and returns the position of all the occurrences of the target, or -1 if it is not in the Listarrow_forwardSuppose that you want an operation for the ADT list that adds an array of items to the end of the list. The header of the method could be as follows: public void addAll( T[ ] items) Write an implementation of this method for the class LinearLinkedListarrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- EBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT