Question: Create a package named, prob1 and a class named, Combine. Write a method named combine that accepts a two ArrayLists, list1 and list2 of the

 Create a package named, "prob1" and a class named, "Combine". Write

Create a package named, "prob1" and a class named, "Combine". Write a method named combine that accepts a two ArrayLists, list1 and list2 of the same length, as arguments. Each List stores integers. The method should return a map where the keys are the elements in list1 and the values are the elements in list2 in reverse order. Thus, the key for the first entry inserted in the map is the first element in list1 and the corresponding value is the last element in list2. The key for the second entry inserted in the map is the second element in list1 and the corresponding value is the next to last element in list 2, etc. You can assume the two lists have the same number of elements. Write a main method using the following test code to create two lists, then call the method combine, and use for-each loop to print out all the entries in the resulting Map. ArrayList list1 = new ArrayList(); list1.add(2); list1.add(4); list1.add(10); list1.add(6); list1.add(8); ArrayList list2 = new ArrayList(); list2.add(1); list2.add(3); list2.add(5); list2.add(7); list2.add(9); The test code should have the following output: Iterating over the map: Key=2 Value=9 Key=4 Value=7 Key=10 Value=5 Key=6 Value=3 Key=8 Value=1

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!