Questions tagged [entryset]

32 questions
0
votes
0 answers

How to sort HashMap when HashMap does not maintain insertion order?

In an interview I was asked to sort HashMap by values. Even after I write such a program, it does not print the HashMap in sorted order. Can someone please explain? public static void main(String[] args) { // TODO Auto-generated method stub …
Prabhat Gaur
  • 146
  • 1
  • 10
0
votes
2 answers

Output from the HashMap containsKey() query not returning the correct value

The program will print the incorrect key and value based on the If statement. Can someone explain why? E.g. Key = Uncle tom + Value = 02086542222 Key = Harry + Value = 020826262 Query = Uncle tom Returns = Key = Harry + Value = 00826262 Quote…
DeCampbell
  • 29
  • 6
0
votes
1 answer

Behavior of contains() and remove() on Set which is returned by entrySet()

I have following code. Why contains & remove returns false? Map p = new TreeMap(); p.put(1, "w"); p.put(2, "x"); p.put(3, "y"); p.put(4, "z"); System.out.println(p);// {1=w, 2=x, 3=y, 4=z} Set s =…
NoOne
  • 141
  • 1
  • 10
0
votes
1 answer

java.util.Map.Entry cannot be resolved error

I tried the following code as package collectconstructor; import java.util.Iterator; import java.util.Map; import java.util.Set; public class QuestionMap { private int id; private String name; private Map answers; …
NDT
  • 13
  • 5
0
votes
1 answer

Unresolved reference: entrySet in Volley

I use the volley library to execute the POST method, but I get the following error: Unresolved reference: entrySet. How can I solve this? Here is my code: Kotlin @Throws(AuthFailureError::class) override fun getBody(): ByteArray? { …
RAL
  • 17
  • 4
0
votes
1 answer

Cannot find symbol when using entrySet() function after import java.util.*

I am using a function Map.entrySet(). When I am using import java.util.* it gives cannot find symbol error. But, when I am doing import java.util.Map.Entry it compiles. Shouldn't "*" include Map.Entry? Am I missing anything? Bottom line using…
Stif Spear Subba
  • 55
  • 1
  • 1
  • 10
0
votes
1 answer

Looping through Set containing Entry objects

import java.util.*; public class HelloWorld{ public static void main(String []args){ HashMap h = new HashMap(); h.put(100,"Hola"); h.put(101,"Hello"); h.put(102,"light"); …
Akash Kaundinya
  • 109
  • 1
  • 6
0
votes
1 answer

Java prints only last entry of HashMap when run without debugger

I want my program print all the entries in HashMap, and it does if I run the app in debugger. But if I run it normaly it prints only the last entry :( Have no idea why it does, Please help me. MoneyCounter: package home.lib; import…
0
votes
2 answers

How to get separate key and value of hashmap without iteration

Here key as difference of latitude and longitude and value as list of String values. I want to do separate key and value of hashmap. Is it possible to do that??? Please suggest me. MainActivity.java public void getExpandableListData() { …
abc
  • 67
  • 3
  • 11
0
votes
0 answers

Using hashMaps with string/integer relation

I've got an issue with some current code. I finished the first half, but now I'm using a hashMap to search this imported text document and find the most used word and the number of times it appears. I had a lot of syntax written and my professor…
guitar138
  • 33
  • 1
  • 1
  • 7
0
votes
1 answer

Add all values to SortedMap (Java)

This is a very simplified excerpt of my code I am using to get the lowest computed value and its parameters using SortedMap: import java.math.BigDecimal; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import…
Tunc Jamgocyan
  • 321
  • 2
  • 7
  • 18
0
votes
1 answer

Why entryset in HashMap calls entryset0?

Why entryset in HashMap calls entryset0 instead of directly writing Set > es = entrySet; ! return es = null es: (entrySet = new EntrySet ()); In the writeObject method directly calls entrySet0, is that because of the reason that…
sangjian
  • 3
  • 1
0
votes
1 answer

How to retrieve Strings from SharedPreferences in the same order as it is stored

I put the String in SharedPreferences like this SharedPreferences preferences = getActivity().getSharedPreferences("Music_playlist", Context.MODE_PRIVATE); SharedPreferences.Editor editor = preferences.edit(); …
shakil.k
  • 1,623
  • 5
  • 17
  • 27
0
votes
2 answers

How do i extract the length of integer array from Map?

How do i extract the length of integer array from a `Map? Map > res = function() ; for (Map.Entry entry : res.entrySet()) { System.out.println(entry.getValue()); } Doing…
ERJAN
  • 23,696
  • 23
  • 72
  • 146
-1
votes
1 answer

SpotBugs warning: Inefficient use of keySet iterator instead of entrySet iterator

Existing Code: Map rolePrincipleMap = cnRoleHolder.getRolePrincipalMap(); Iterator cnRoleIterator = rolePrincipleMap.keySet().iterator(); while (cnRoleIterator.hasNext()) { Object…