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_2

Step: 3

blur-text-image_3

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

DB2 Universal Database V7.1 Application Development Certification Guide

Authors: Steve Sanyal, David Martineau, Kevin Gashyna, Michael Kyprianou

1st Edition

0130913677, 978-0130913678

More Books

Students also viewed these Databases questions

Question

Does it avoid typos and grammatical errors?

Answered: 1 week ago