Category "hashmap"

how to resolve this sonarQube bug about hashmap in java

I have a hashMap : private static Map<String, JSONObject> laserDataList = new HashMap<String, JSONObject>(); I wrote this part of code : public void

How can I spoof prop values that don't belong to android.os.Build?

With the following segment of code I'm able to spoof certain build.prop parameters such as brand, manufactuer, device, product and model: data class DeviceEntri

How to print amount of occurrences of specific string in descending order?

I'm looking to use a String[] of logs detailing users who have connected to a website to print out in descending order the amount of times each user has connect

Check 2 keys for Vacant

I am using the HashMap to store some of the value. Now I want to check whether HashMap contains keys, if not insert data else return HashMap is not empty. Below

Compare HashMap Values structured as List [closed]

I have a HashMap structured like {a=[test], b=[test, test2]} I want to compare entry values (test, test2) with each other and if any entry ha

How to remove Keys that would cause Collisions before executing Collectors.toMap()

I have a stream of objects similar to this previous question, however, instead of ignoring duplicate values, I would like to remove any values from that stream

How to return a Key from HashMap based on its Value in Java

Consider the following: for (Boolean i: x.values()) { if (i == false) { return // KEY; } } In the above code, I am trying to iterate through th

In java map, I want to assign the repository functions as value like Map<key, function(>

I Want to call the JPA repository functions to access the data from the database based on the String value passed. So I want to make the string as the key and t

Why HashMap put so much faster after jdk8?

Why does this class, built with Java 8, run ~5x faster on Java 11 than Java 8? import java.time.Duration; import java.time.LocalDateTime; import java.util.HashM

Groovy LinkedHashMap returned from a Jenkins shared library is converted to String

I have a function in a Jenkins shared library which builds and returns a map object (class java.util.LinkedHashMap): #!/usr/bin/env groovy def call(Map config)

How to insert records into a Nested HashMap?

I want to create a nested HashMap of: var myHashMap = new HashMap<String, HashMap<String, int>>(); And I want to insert records into the inner Hash

How to create a matrix with key and value in java

I have this table with these values I have this code in java import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map;

How to use Map.computeIfAbsent() in a stream?

I have a fun puzzler. Say I have a list of String values: ["A", "B", "C"] Then I have to query another system for a Map<User, Long> of users with an attr

Rewrite imperative code of creating and populating Map in a declarative way using Java Stream API

I have this piece of code : Map<String, BillingAccount> billingAccountsMap = new HashMap<>(); for (BillingAccount ba : billingAccounts) { if (ba

How to create a unique key for a map

I'm creating a structure where a developer can store a reference to something and retrieve it when needed using a reference key, but not delete the reference. H

Maximum Frequency Number in an array using Hashmaps

Problem: You are given an array of integers that contain numbers in random order. Write a program to find and return the number which occurs the maximum

Hashmap values always being overwritten to last looped value

I cannot figure out why my HashMap keeps over writing all of my key/value pairs with the last ip address the method reads. Basically we are meant to store all o

hashCode values not same in debugger and output in netbeans 8.2

Map<String, Integer> map = new HashMap<>(); map.put("Naveen", 100); System.out.println("Naveen".hashCode()); /* output (-1968696341)

Get list of keys in Complex JSON Object (Java 8)

I am dealing with a JSON that looks like this :- { "key1": { "key1.1": { "nestedkey1": "something", "nestedkey2": "something", "nest

How to convert List to Map?

Recently I have conversation with a colleague about what would be the optimal way to convert List to Map in Java and if there any specific benefits of doing so.