I have one List of totally 13 HashMaps in my input. Each HashMap has only 2 Keys "fieldName" and "accessibilityType" and corresponding values:  "fieldAccessibility": [     {         "fieldName": "firstName",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "lastName",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "avatarUrl",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "username",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "birthDate",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "phoneNumbers",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "email",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "language",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "externalId",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "externalCode",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "punchBadgeId",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "minor",         "accessibilityType": "EDITABLE"     },     {         "fieldName": "seniorityDate",         "accessibilityType": "EDITABLE"     } ]   I am trying to iterate through this and change the value of "accessibilityType" into "READ" where "fieldName" is "birthDate". Can someone please say the efficient way to do this. This is my attempt so far to just read and print each key-value pair:  final List&lt;HashMap&lt;String, String&gt;&gt; list = some code to get the input;     for (HashMap&lt;String, String&gt; m : list)     {         for (HashMap.Entry&lt;String, String&gt; e : m.entrySet())         {             String key = e.getKey();             String value = e.getValue();              System.out.println("SEE HERE TEST " + key + " = " + value);          }}
93
I've been using the == operator in my program to compare all my strings so far. However, I ran into a bug, changed one of them into .equals() instead, and it fixed the bug.  Is == bad? When should it and should it not be used? What's the difference?
59203
I have a the following dictionary:  IDictionary&lt;int, IList&lt;MyClass&gt;&gt; myDictionary    and I am wanting to get all the values in the dictionary as an IList....    Just to add a bit of a background as to how I've gotten into this situation....  I have a method that gets me a list of MyClass. I then have another method that converts that list into a dictionary where they key is the id for MyClass. Later on...and without access to that original list...I'm needing to obtain the original ungrouped list of MyClass.    When I pass myDictionary.Values.ToList() to a method that takes an IList I get a compile error that says that it can't convert from   System.Collections.Generic.List&lt;System.Collections.Generic.IList&lt;MyClass&gt;&gt;    to:  System.Collections.Generic.IList&lt;MyClass&gt;   Now, I can understand that its gone and added each of the groups of IList to the new list as separate elements of the list....but in this instance its not really what I'm after. I just want a list of all the values in the entire dictionary.  How then can I get what I'm after without looping through each of the key values in the dictionary and creating the list I want?
54815
I'm looking for a class in java that has key-value association, but without using hashes.  Here is what I'm currently doing:   Add values to a Hashtable. Get an iterator for the Hashtable.entrySet(). Iterate through all values and:   Get a Map.Entry for the iterator. Create an object of type Module (a custom class) based on the value. Add the class to a JPanel.  Show the panel.   The problem with this is that I do not have control over the order that I get the values back, so I cannot display the values in the a given order (without hard-coding the order).  I would use an ArrayList or Vector for this, but later in the code I need to grab the Module object for a given Key, which I can't do with an ArrayList or Vector.  Does anyone know of a free/open-source Java class that will do this, or a way to get values out of a Hashtable based on when they were added?  Thanks!
15484
Is it possible to automate the process of picklist values retrieval from the backend?  Here is how I am doing it right now:  @AuraEnabled public static List&lt;String&gt; retrieveMyObjectMyFieldOptions() {     List&lt;String&gt; res = new List&lt;String&gt;();      Schema.DescribeFieldResult fieldResult             = MyObject__c.MyField__c.getDescribe();     List&lt;Schema.PicklistEntry&gt; ple = fieldResult.getPicklistValues();     for(Schema.PicklistEntry f: ple) {         res.add(f.getLabel());         res.add(f.getValue());     }      return res; }   Is it possible to pass two strings to a method and get the same list as above? In other words is it possible to change the signature to the following:   public static retrieveMyObjectMyFieldOptions(String MyObject, String MyField)?
2961
I have a JavaScript object like the following:  var p = {     "p1": "value1",     "p2": "value2",     "p3": "value3" };   Now I want to loop through all p elements (p1, p2, p3...) And get their keys and values. How can I do that?  I can modify the JavaScript object if necessary. My ultimate goal is to loop through some key value pairs and if possible I want to avoid using eval.
827
If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it,  what is the most efficient way of going through the map?  Will the ordering of elements depend on the specific map implementation that I have for the interface?
90963
Did you know that :  Map&lt;Object,Object&gt; m1 = new HashMap&lt;Object, Object&gt;(); Map&lt;Object,Object&gt; m2 = new HashMap&lt;Object, Object&gt;(); System.out.println("m1.equals(m2) = "+m1.equals(m2)); System.out.println("m1.keySet().equals(m2.keySet()) = "             +m1.keySet().equals(m2.keySet())); System.out.println("m1.entrySet().equals(m2.entrySet()) = "             +m1.entrySet().equals(m2.entrySet())); System.out.println("m1.values().equals(m2.values()) = "             +m1.values().equals(m2.values()));   would output :  m1.equals(m2) = true m1.keySet().equals(m2.keySet()) = true m1.entrySet().equals(m2.entrySet()) = true m1.values().equals(m2.values()) = false   This is caused by the fact that AbstractCollection (which HashMap$Values inherits from) does not overrides #equals().  Do you have an idea why this is so ?
28594
Given a list of strings, I want to sort it alphabetically and remove duplicates. I know I can do this:  from sets import Set [...] myHash = Set(myList)   but I don't know how to retrieve the list members from the hash in alphabetical order.  I'm not married to the hash, so any way to accomplish this will work. Also, performance is not an issue, so I'd prefer a solution that is expressed in code clearly to a fast but more opaque one.
120888
How can I get the last value of an ArrayList?  I don't know the last index of the ArrayList.
80428
I have a class like this:  public class myClass {   public List&lt;myOtherClass&gt; anewlist = new List&lt;myOtherClass&gt;;    public void addToList(myOtherClass tmp)   {     anewList.Add(tmp);   }  }   So I call "addToList" a hundred times, each adding a unique item to the list.  I've tested my items to show that before I run the "addToList" method, they are unique.  I even put a line in to test "tmp" to make sure it was what I was expecting.  However, when I do this (lets say myClass object is called tmpClass):  int i = tmpClass.anewList.Count(); for (int j = 0; j&lt;i; j++) {    //write out each member of the list based on index j... }   I get the same exact item, and it's the last one that was written into my list.  It's as if when I add, I'm overwriting the entire list with the last item I've added.    Help?  This makes no sense. I've also tried List.Insert, where I'm always inserting at the end or at index 0.  Still no dice.  Yes, I'm doubly source my indexing is correct and when I do my test I'm indexing through each of the elements.  :)  UPDATE: Okay, I tried this and still had the same problem:  foreach(myOtherClass tmpC in tmpClass.anewList) {         Console.WriteLine(tmpC.theStringInMyClass.ToString()); }   and still for each of the 100 items, I got the same string output... I'm sure I'm doing something completely stupid, but I don't know what yet. I'm still 100% sure that the right string is getting passed in to begin with.  -Adeena    Okay, I tried this and still had the same problem:  foreach(myOtherClass tmpC in tmpClass.anewList) {     Console.WriteLine(tmpC.theStringInMyClass.ToString()); }   and still for each of the 100 items, I got the same string output...  I'm sure I'm doing something completely stupid, but I don't know what yet. I'm still 100% sure that the right string is getting passed in to begin with.  -Adeena
113672
For example:  &gt;&gt;&gt; x = [1, 1, 2, 'a', 'a', 3] &gt;&gt;&gt; unique(x) [1, 2, 'a', 3]   Assume list elements are hashable.  Clarification: The result should keep the first duplicate in the list. For example, [1, 2, 3, 2, 3, 1] becomes [1, 2, 3].
89428
I have a field in a list that accepts an SPFieldUser object. I have an SPUser object that I would like to populate that field with, but I cannot implicitly convert from one to the other.  How would I do this conversion?
112859
Is there a better way to do this?  string[] s = {"zero", "one", "two", "three", "four", "five"};  var x =  s .Select((a,i) =&gt; new {Value = a, Index = i}) .Where(b =&gt; b.Value.StartsWith("t")) .Select(c =&gt; c.Index);   i.e. I'm looking for a more efficient or more elegant way to get the positions of the items matching the criteria.
56415
I have four foreach loops that iterate through the collections and based on a condition do something.   Here is the code that I am writing now:  boolean breakFlag = false; String valueFromObj2 = null; String valueFromObj4 = null; for(Object1 object1: objects){   for(Object2 object2: object1){     // I get some value from object2     valueFromObj2 = object2.getSomeValue();     for(Object3 object3 : object2){       for(Object4 object4: object3){        // Finally I get some value from Object4.        valueFromObj4 = object4.getSomeValue();        // Compare with valueFromObj2 to decide either to break all the foreach loop        breakFlag = compareTwoVariable(valueFromObj2, valueFromObj4 );        if(breakFlag){break;}       } // fourth loop ends here       if(breakFlag){break;}     } // third loop ends here     if(breakFlag){break;}   } // second loop ends here   if(breakFlag){break;} } // first loop ends here   The main object (objects in the code) comes from a third-party provider SDK, so I cannot change anything on that portion. I want to ask the Stack&nbsp;Overflow community if there is a better approach to break all the four foreach loops. Or if there is any other way to refactor this code to make it more readable and maintainable.
92538
I'd like to create a Dictionary object, with string Keys, holding values which are of a generic type. I imagine that it would look something like this:  Dictionary&lt;string, List&lt;T&gt;&gt; d = new Dictionary&lt;string, List&lt;T&gt;&gt;();     And enable me to add the following:  d.Add("Numbers", new List&lt;int&gt;()); d.Add("Letters", new List&lt;string&gt;());   I know that I can do it for a list of strings, for example, using this syntax:  Dictionary&lt;string, List&lt;string&gt;&gt; d = new Dictionary&lt;string, List&lt;string&gt;&gt;(); d.Add("Key", new List&lt;string&gt;());   but I'd like to do it for a generic list if possible...  2 questions then:   Is it possible? What's the syntax?   Many thanks, Jon
37684
I'm trying create a Map using a name field as key.  Sample code:  Set&lt;String&gt; priceBooksNames = new Set&lt;String&gt;(); priceBooksNames.add('LN-200'); priceBooksNames.add('LN-100');  Map&lt;string,PriceBook2&gt; priceBooks = new Map&lt;string,PriceBook2&gt;([SELECT name,id FROM PriceBook2 WHERE name=:priceBooksNames ]); system.debug(priceBooks.get('LN-100')); //this is returning NULL   I can see on console that setId on map is not getting the name field value.  VARIABLE_ASSIGNMENT [5]|priceBooks|{"serId":1,"value":{"01sb0000000hiqQAAQ":{"serId":2,"value":{"Name":"LN-100 ADULTOS","Id":"01sb0000000hiqQAAQ"}},"01sb0000000hiqGAAQ":{"serId":3,"value":{"Name":"LN-200 EMPRESAS","Id":"01sb0000000hiqGAAQ"}}}}   What I'm going wrong?
3070
I have a form that has multiple fields, and for testing purposes is there a way I could print out the values entered in all the fields, without having to individually print each value.