Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Given an arraylist of strings. Write a method to sort the arraylist alphabetically and display the sorted elements with the number of times they occurred

Given an arraylist of strings. Write a method to sort the arraylist alphabetically and display the sorted elements with the number of times they occurred in the arrayList (don't print the same element twice). Is there a way to do this without using hash maps? Say I want to use insertion sort. say arraylist is: ("b", "a", "c", "c", "a", "b", "b") output should be: a 2 b 3 c 2 here what I have so far for insertion sort.

public static > void sortAlphabetically(ArrayList arrList) { for(int i = 1; i < arrList.size(); i++) { AnyType temp = arrList.get(i); int j = i; for( ; j > 0 && temp.compareTo(arrList.get(j-1)) < 0; j--) { arrList.set(j, arrList.get(j-1)); } arrList.set(j, temp); } } Now, I just need some way to keep track of the number of duplicates and display the elements (only once each if they are duplicated). I probably will need a new array list. 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

3rd Edition

0128012757, 978-0128012758

More Books

Students also viewed these Databases questions

Question

3 The distinction between microeconomics and macroeconomics.

Answered: 1 week ago

Question

2 The role of economic theory in economics.

Answered: 1 week ago