I wrote the code below, where from an initialized list of countries the method will return all the countries who have a longitude of >= 5, the code works but now I want the method to return the name of countries that are close to String D within a 5 degrees range of longitude. I tried implementing the scanner as
Tag: sorting
How to sort the hashmap in descending order by values and if the values are the same then by key in ascending order
I have a HashMap<Integer, Integer> named “relevance” e.g {2: 3, 1: 3, 3: 3, 5: 4, 4: 4, 6: 3} and I want do DESC sorting by values. I get a hashmap {5: 4, 4: 4, 2: 3, 1: 3, 3: 3, 6: 3}. How can I sort ascending keys with the same values? Answer You can “chain” Comparators by
How to use arrayList sort and manipulate the vlaue
By using Java 11, I am trying to find the average value inside the ArrayList. The algorithm i want to develop is ((value inside list/maximum value)*100)/length of list). I got number format runtime error while I run the program. java.lang.NumberFormatException is the error i got. enter image description here Answer I find two issues with the code above: The parsing
Compute time to find an element (number) in an array using linear Search
So I got this question in my assignment and I did almost all other than the last part, the code works fine. The question I got is mentioned below. Write a program to generate any number of random integers in 0 to 100 range. Your program should get the size as a parameter and return the numbers as an array.
Sorting LinkedHashMap<String, ArrayList> by counting the occurrences in ArrayList problem
I have: How can i sort “maps” by counting the occurrences in “miss”? For example: miss => [3, 7] maps => {1=[0, 3, 6], 4=[2, 3, 4], 6=[0, 3, 7], 11=[1, 3, 6], 17=[2, 6, 11]} And i want to get: maps => {6=[0, 3, 7], 1=[0, 3, 6], 4=[2, 3, 4], 11=[1, 3, 6], 17=[2, 6, 11]} Answer The
Difficulty trying to sort 10 numbers inputted by a user. Must use arrays and a separate method for sorting
My program isn’t sorting the numbers at all. It displays them in the order they were initially entered. It must sort them from smallest to largest number. The code below should find the largest number in the array and swap it with the last .the code is below: Answer I believe your problem is here: array.length is not less than
How to sort the keySet() of a TreeMap with keys containing number?
I’ll briefly describe what I did and then show how the result I got, differs from my desired result. Thanks in advance for any suggestions. Java code was created in a java online compiler and is executable there without error message in any case. Java online compiler, which was used Short description: I want to assign a boolean value to
Sort collection according to user custom input by single or multiple attributes
I have collection of Item object and the class Item is as follows -> Now, I want to sort according to the user input. User can sort it according to his choice like brand, price or publishedDate and even with the multiple parameters. Like brand and price or price and publishedDate. I have seen Comparator to sort by multiple parameters
Sort List of Values in a Map in descending order
I have a Map with List of Doubles. unsorted map contents: {A=[0.02, 0.03], B=[0.0, 0.01], C=[0.01, 0.0], D=[0.05, 1.03], E=[1.01, 0.03]} I need to sort in descending order for List(0). I have tried the below logic but its sorting in ascending order. Actual output: {B=[0.0, 0.01], C=[0.01, 0.0], A=[0.02, 0.03], D=[0.05, 1.03], E=[1.01, 0.03]} Expected output: {E=[1.01, 0.03], D=[0.05, 1.03],
JAVA – Sort Array of Json by multiple values while preserving previous sort order
I have this json and I want to be able to sort it by multiple field values of different types while retaining the previous sort order. The fields by which I should decide to sort it are given through another json: I managed to achieve this by converting the json array to a list of Hashmap<String,Object> and wrote a custom