How to get value from map [duplicate] - java

This question already has answers here:
Converting JSON data to Java object
(14 answers)
Closed 7 years ago.
I have one map file
Map<String,Object> personData = procReadData.execute(in);
The data is coming from this is
{CUR_GENERIC=[{PROPOSAL_NUMBER=1, TITLE=test proposal, LEAD_UNIT_NAME=University, FULL_NAME=test, STSTUS_CODE=Pending, DOCUMENT_TAKEN_BY=user1 qa, UPDATE_TIMESTAMP=2015-12-28 00:00:00.0, UPDATE_USER=test}]}
How to get PROPOSAL_NUMBER from that result.

You should check what type the result of
personData.get("CUR_GENERIC");
is (use a debugger for this if you have no documentation available). It's probably a list or an array of Map<String, Object> depending on what tool was used to convert the JSON data to a Java map. Get the first entry of this list or array and then use get("PROPOSAL_NUMBER") to retrieve the entry you want.

Related

NSPredicate type search is available in Java/Android or not? [duplicate]

This question already has answers here:
Java List.contains(Object with field value equal to x)
(13 answers)
Is there a java equivalent to NSPredicate?
(1 answer)
Closed 5 years ago.
In the IOS, we need to search an item or name easily find using the NSPredicate on NSArray or collection. This NSPredicate is executing very faster and give the results exactly few seconds
In the Android or Java any NSPredicate type search available? Can you please suggest.
I have LiSt object, It contains "n" number of objects. So, I want search an item name or value is exist in this object or not. If the item is exist to get those items. In IOS it is easy to get the Items using the NSPredicate.
So using java is it possible to fetch the item in the List object. When we use the default for loop it takes lot of time to execute and find the elements.

Java 8: Map of field to list of items [duplicate]

This question already has answers here:
Java 8 lambdas group list into map
(2 answers)
Closed 5 years ago.
Lets say I have a List<Person> Gathering and I want a Map<String, List<Person>>, mapping Person.surname to a List of Person:s that have the same surname. Is there a convenient way to do this using streams?
Yes, by using Collectors.groupingBy(...):
Map<String, List<Person>> personsBySurname = gathering.stream()
.collect(Collectors.groupingBy(Person::get‌​Surname));

How to put value in HashMap? [duplicate]

This question already has answers here:
How to initialize an array in Java?
(11 answers)
Closed 6 years ago.
I have a Map
Map<String,String[]> data = HashMap<String,String[]>();
and want to put value in it. like
"key":["value1","value2"]
I try it but get error:
data.put("key",["value1","value2"]);//syntax error
You could try using the Array initializer for fixed size string arrays like following
Map<String, String[]> data = new HashMap<>();
data.put("key", new String[]{"val1", "val2"});
This should definitely work

How to convert HashSet to byte[]? [duplicate]

This question already has answers here:
Java Serializable Object to Byte Array
(12 answers)
Closed 8 years ago.
I have requirement where i want to store Hash Set i have to byte[] in database. I have searched through internet haven't found a solution.
I have following hashset of custom class.
HashSet<MyClass> set = new HashSet<MyClass>();
Please help.
You can serialize it, if the stored data is serializable. Then convert to bytes.

Retrieve values from hashmap (.values()) [duplicate]

This question already has answers here:
How do I convert a Map to List in Java?
(13 answers)
Closed 9 years ago.
I would be pleasure if you can suggest.
Could you suggest how properlly I can retriev all values from hashmap.
In such simplee example:
Map<String, Values> someMap = ....;
List<Values> valuesFromMap = (List<Values>) someMap.values();
After that I've got that, Java couldn't cast to java.util.List
Thank you in advanced.
The values method returns a Collection, not a List. Use
Collection<Values> valuesFromMap = someMap.values();
someMap.values() returns Collection. If you need to convert into List than do that as follows:
List<Values> valuesFromMap = new ArrayList<>(someMap.values());

Categories