Explanation of Solution
Method “maxOccurrences()” to return the number of common integers in the two list:
//import the required packages
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
//define the class
public class Test
{
//define the static method
public static void main(String[] args)
{
//create a set
List<Integer> stringsSet=new ArrayList<Integer>();
//add the values to list 1
stringsSet.add(3);
stringsSet.add(7);
stringsSet.add(3);
stringsSet.add(3);
stringsSet.add(2);
stringsSet.add(3);
stringsSet.add(3);
//Call the method
System.out.println(maxOccurrences(stringsSet));
}
//Definition of method maxOccurences
public static int maxOccurrences(List<Integer> list)
{
//Create an object counts
Map<Integer, Integer> counts = new HashMap<Integer, Integer>();
//Traverse the list
for (int value : list)
{
//Check whether the value present in the list
if (counts...
Want to see the full answer?
Check out a sample textbook solutionChapter 11 Solutions
Building Java Programs: A Back To Basics Approach, Loose Leaf Edition (5th Edition)
- 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