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
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
What is the ArrayList list's starting size?
not sure how to do this problem output doesnt matter
How can an ArrayList be used?
Chapter 20 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th 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
- What are the methods for evaluating the efficiency of an ArrayList?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| 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_forward
- What is an annotation? How are annotations useful in writing our ArrayList<E> class?arrow_forwardP__Given an empty ArrayList<Integer> numList, what are numList's contents after the following operations: numList.add(12);numList.add(14);numList.add(16);numList.set(1, 13);numList.add(0, 10);.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_forwardjava 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_forward
- The 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_forwardWe can access the element using subscript directly even if it is somewhere in between, we cannot do the same random access with a linked list. * True O Falsearrow_forward· Write a method to insert an element at index in a Doubly Linked List data structure and test it. The method receives this list by parameters. * in javaarrow_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