# Tag: sorting

## Radix sort with counting sort incorrectly sorts letters converted to binary

I’m having trouble understanding why my code for radix sort with counting sort doesn’t correctly sort the input when I convert it to binary. I’m basically using the same code for letters represented as decimal and they work just fine but here it isn’t even close. Below is the code that takes part in binary radix sort: console: another case:

## How to implement a benchmark for a java mergesort program?

I want to implement a benchmark where the Method MergeSort and it’s performance is measured. I have tried to fill the array that is to be mergesorted with random numbers but when the code is run the array prints the same random number 10 times. Why is this? PS. I can’t post the entire program I have written. Stackoverflow is

## Sort String of Characters Using Hashed Array and Java 8 Streams

I stumble upon this cool sorting algorithm with O(n) time complexity on GeeksforGeeks – Sort string of characters and I was trying to refactor the code to use Java Streams on the nested for loops instead and collect the result in a string variable but I can’t seem to wrap my head around it. Here’s the original code: Answer Try

## Print the contents of a HashMap in sorted order according to the Size of each HashMap nested inside the given HashMap

I have a HashMap inside a HashMap. I want to print the elements in the HashMap according to the size of elements in the inner HashMap. So the element with the highest number of elements should print first. I’m new to HashMaps and got stuck. This is the HashMap and how I’m printing it: The output that I’m currently getting:

## Why isn’t my selection sort program working?

I am trying to create my own program to do selection sort on an array of integers. I have come up with the following program, which works on some arrays, but not on others, such as this one. I have been trying to trace the problem, and I think it might have to do with where I am placing the

## How to Peek the Lowest elements from a List of sorted Streams continously

I started learning about Java Stream, and I am wondering is it possible to only peek the first element of the stream without retrieving it. For example, I have multiple streams, and each of them have integers that are sorted in non-decreasing order, and I want to get a sorted list of all integers, so I’m thinking about using a

## Sort a List of objects based in its Sublist method size

I’m trying to make my own “Facebook reaction bar” and I got into a problem, I need to sort a list of objects based in its sublist method size, let me explain! I have a ReactionModel which has a property “usernames” which is a List of Strings of usernames of those users that used it. I have a list of

## Sorting an arraylist with lambda function isn’t working

I’m trying to use .sort() method with an arraylist. My method public void sortSurname() should sort alphabetically all the objects by their surname, these objects are contained in an arraylist ArrayList<Contact> contacts. Could someone please find the issue with this code? Here is what I’ve written so far: Contact class Rubrica class Main Thank you for the help. Answer The

## Sorting a List of Maps dynamically in Ascending and Descending order

I am having Maps inside a List. I need to sort the List based on the input dynamically by passing it as a parameter into the method sortData. It is working as expected, but the problem is that am not able to sort the list in reverse order. I’m getting an Error : The method get(String) is undefined for the

## Sort 2d String array by integer in first column

I have a 2d array in Java 8: String data[][] = new String[i][2]; And it looks like this: Player1 8 Player5 3 Player3 9 Player4 5 … and I want to sort it to have the highest score at the top: Player3 9 Player1 8 Player4 5 Player5 3 How can I sort this or is there a better way