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
Question
Chapter 21.4, Problem 21.4.2CP
Program Plan Intro
Set:
Set is a data structure that is used for storing and processing non duplicate elements. It is an interface which extends collection and it is an unordered collection of objects.
Set is implemented by LinkedHashSet, HashSet or a TreeSet.
Hash Set:
In order to store its elements internally, the HashSet uses HashMaps and it implements the Set interface, backed by a hash table which is actually a HashMap instance.
ArrayList:
ArrayList provides dynamic arrays in Java and is a part of collection framework and is present in java.util package.
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
Q: Convert this to sorted array
#include<iostream>
#include"Student.cpp"
class StudentList
{
private:
struct ListNode
{
Student astudent;
ListNode *next;
};
ListNode *head;
public:
StudentList();
~StudentList();
int IsEmpty();
void Add(Student newstudent); void Remove();
void DisplayList();
};
StudentList::StudentList() {
head=NULL;
};
StudentList::~StudentList()
{
cout <<"\nDestructing the objects..\n";
while(IsEmpty()!=0)
Remove();
if(IsEmpty()==0)
cout <<"All students have been deleted from a list\n"; };
int StudentList::IsEmpty()
{
if(head==NULL)
return 0;
else
return 1;
};
void StudentList::Add(Student newstudent) {
ListNode *newPtr=new ListNode;
if(newPtr==NULL)
cout <<"Cannot allocate memory";
else
{
newPtr->astudent=newstudent;
newPtr->next=head;
head=newPtr;
}
};
void StudentList::Remove() {
if(IsEmpty()==0)
cout <<"List empty on remove"; else
{
ListNode *temp=head;…
Remove Char
This function will be given a list of strings and a character. You must remove all occurrences of the character from each string in the list. The function should return the list of strings with the character removed.
Signature:
public static ArrayList<String> removeChar(String pattern, ArrayList<String> list)
Example:list: ['adndj', 'adjdlaa', 'aa', 'djoe']pattern: a
Output: ['dndj', 'djdl', '', 'djoe']
The last part of the code is not completed.
public static void displayArray(int[] list)
{
System.out.println("The sum resulting array is" + Arrays.toString(list));
}
}
Chapter 21 Solutions
Introduction to Java Programming and Data Structures: Brief Version (11th Global 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
- Correct the following code so that it correctly initializes and outputs the elements of the array intList. int intList [5];for (int i = 0; i > 5; i--)cin >> intList [i];for (int i = 0; i < 5; i--)cout << intList << " ";cout << endl;arrow_forward6. Consider the following code segment: ArrayList list = new ArrayList(10) ; list.add( "Ali" ); list.add( "Ahmed" ); list.add( "Hassan" ); list.add( 0, "Qasim" ); Which of the following elements will be at index 1 of the list? K Ali Ahmed Hassan Qasimarrow_forwardT/F Suffix array can be created in O(nlogn) time.arrow_forward
- Question Completion Status: Write a Java program that uses ArrayList and Iterator, It should input from user the names and ages of your few friends in a loop and add into ArrayList. Finally, it should use an terator to display the data in a proper format. (Sample run of the program) List of my Friends Enter name and age [friend# 0] Khalid Al-shamrí 22.5 Do you want to add another friend (y/ny? y Enter name and age [friend# 1] Rahsed Al anazi 21.1 Do you want to add another friend (y/ny? y Enter name and age (friend# 2] Salem Al mutaits 23.7 Click Save and Submit to save and submit. Click Save All Answers to save all answers. Save Aarrow_forward8. To create a list to store integers, use a. ArrayList list = new ArrayList() ; w w b. ArrayList list = new ArrayList(); www c. ArrayList list = new ArrayList(); d. ArrayList list = new ArrayList(); w warrow_forwardUsing C Sharp, Declare an array animals with 5 animals in it such as “dog”, “cat”, etc. After the declaration write the code to add another animal to the array. Write the code to add each animal to a list box called lstAnimals.arrow_forward
- What distinguishes When will Array be preferred to Array List an array from an array list?arrow_forwardWhat is the ArrayList list's starting size?arrow_forward2. ID: A Name: 2. A list of numbers is considered increasing if each value after the first is greater than or equal to the preceding value. The following procedure is intended to return true if numberList is increasing and return false otherwise. Assume that numberList contains at least two elements. Line 1: PROCEDURE isIncreasing (numberList) Line 2: { Line 3: count 2 Line 4: REPEAT UNTIL(count > LENGTH(numberList)) Line 5: Line 6: IF(numberList[count] =. YA198ICarrow_forward
- What happens when your program attempts to access a list element with an invalid index?arrow_forwardThe ArrayList is created using the following syntax: String[] array = {"red", "green", "blue"}; ArrayList list Display all the elements of this list using: a) foreach loop b) foreach method with lambda := new ArrayList(java.util.Arrays.asList(array));arrow_forwardWhat happens when your program attempts to access an array element with an invalid index?arrow_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