How do I replace value of Map if the key is present?

I have this map: Map<String, String> myMap = new HashMap<>(); I’m trying to check if this map has a key called "Brian". If – and only if – it does, I want to replace the value with "Hello". If I understand correctly the computeIfPresent method does exactly that, but it expects a remappingFunction as the… Read More How do I replace value of Map if the key is present?

App crashes when getting current user's location (Kotlin)

My code compiles but the app will not start now. I’ve tried many variations to simply get a user’s current location and display it using MapsSDK but nothing works. Fragment Activity: class BuyFragment : Fragment(), OnMapReadyCallback { private var _binding: FragmentBuyBinding? = null private val binding get() = _binding!! private lateinit var map: GoogleMap private… Read More App crashes when getting current user's location (Kotlin)

How do I get the sum of all values in a map with multiple values?

PROBLEM I have a map that looks like this: const myMap= new Map(); myMap.set("MapItem1", [1, 4.5]); myMap.set("MapItem2", [0, 3]); myMap.set("MapItem3", [1, 10]); myMap.set("MapItem4", [1, 1]); As you can see, this map has 1 key, and an array with 2 values. What I’m trying to do is get the sum of all the second values. Solution… Read More How do I get the sum of all values in a map with multiple values?

how to sort a map in flutter by it's key

Hello i am trying to sort a map in flutter and i have encountered several methods but none have helped so far. { 11-Mittwoch: 07:20:58-07:21:03-23:44:37-00:00:00, 15-Sonntag: 11:11:02-11:11:32-00:00:29-00:00:00, 10-Dienstag: 07:36:20-07:20:53-23:44:32-00:00:00, 28-Samstag: 15:32:18-15:32:21-00:00:01-00:00:01, 30-Montag: 08:25:50-16:28:57-08:03:06-00:00:00, 1-Sonntag: 20:39:11-20:39:33-00:00:15-00:00:06, 3-Dienstag: 17:30:14-17:30:19-00:00:04-00:00:00, 18-Mittwoch: 07:54:51-17:38:01-09:43:09-00:00:00, 5-Donnerstag: 08:17:11-22:07:50-03:45:09-10:05:28, 17-Dienstag: 07:00M-15:20M-7:00M-1:00M, 9-Montag: 18:10:28-18:10:32-00:00:04-00:00:00, 6-Freitag: 07:36:54-14:56:13-07:19:19-00:00:00, 2-Montag: 08:28:39-15:44:11-04:21:33-01:05:34} as you can see from the… Read More how to sort a map in flutter by it's key

I need to put an array of integers into a map, key is number of digits using stream

Hi so i have an array of integers and i have to put it into a map key is number of digits. I know i should use stream groupingBy but i have a problem. i have this piece of code: public static Map<Integer, List<String>> groupByDigitNumbers( List<Integer> x){ return x.stream() .collect(Collectors.groupingBy(n->Integer.toString(n).length())); } but my values should… Read More I need to put an array of integers into a map, key is number of digits using stream

Comparing 2 HashMap with Key as String and Value as UserDefined Object

I want to output a boolean as true indicating both maps have same Key and values. If i use equals() it returns false. How can i output as true , Object references are different. But the entries are same I have 2 maps below Map<String,Information> map1=new HashMap<>(); map1.put("key1", new Information("10","20","30","40")); map1.put("key2", new Information("11","22","33","44")); Map<String,Information> map2=new… Read More Comparing 2 HashMap with Key as String and Value as UserDefined Object