Why I get -1 returned? For sure the name is in stadiumSeats[i][j].  `public int searchForGuest(final String name){            for(int i=0; i&lt;stadiumSeats.length; i++){         for(int j=0; j&lt;stadiumSeats.length; j++){             if(stadiumSeats[i][j] == name){                 return i;             }         }     }     return -1; }`
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?
52567
When is it appropriate to use an unsigned variable over a signed one? What about in a for loop?  I hear a lot of opinions about this and I wanted to see if there was anything resembling a consensus.   for (unsigned int i = 0; i &lt; someThing.length(); i++) {       SomeThing var = someThing.at(i);       // You get the idea.   }   I know Java doesn't have unsigned values, and that must have been a concious decision on ' part.
7551
Is there a better way to negate a boolean in Java than a simple if-else?  if (theBoolean) {     theBoolean = false; } else {     theBoolean = true; }
87341
An array is defined to be maxmin equal if it contains at least two different elements and the number of times the maximum value occur is the same as the number of times the minimum value occur. So {11, 4, 9, 11, 8, 5 , 4, 10} is maxmin equal, because the max value 11 and min value 4 both appear two times in the array.   if the input array is {} , isMaxMinEqual should return false (array must have at least two different elements) status = false; if the input array is {2}, isMaxMinEqual should return false (array must have at least two different elements). if the input array is {1,1,1,1,1,1}, isMaxMinEqual should return false (array must have at least two different elements).  if the input array is {2,4,6,8,11}, isMaxMinEqual should return true (Both max value(11) and min value 2 appear exactly one time). if the input array is {-2,-4,-6,-8,-11}, isMaxMinEqual should return true(Both max value(-2) and min value -11 appear exaclty one time).   I wrote the class MaxMin which satisfied the above condition.  public class MaxMin {  public static void main(String args[]) {     System.out.println("The result is: " + isMaxMinEqual(new int[]{2, 2})); }  public static boolean isMaxMinEqual(int[] a) {     boolean status = false;     int count = 0;     if (a.length &lt; 2) {         status = false;         return status;     }     for (int i = 1; i &lt; a.length; i++) {         if (a[i - 1] != a[i]) {             count++;         }     }      int max = a[0];     int min = a[0];     for (int i = 0; i &lt; a.length; i++) {         if (a[i] &gt; max) {             max = a[i];         } else if (a[i] &lt; min) {             min = a[i];         }     }      int maxCount = 0;     for (int j = 0; j &lt; a.length; j++) {         if (a[j] == max) {             maxCount++;         }     }      int minCount = 0;     for (int j = 0; j &lt; a.length; j++) {         if (a[j] == min) {             minCount++;         }     }     System.out.println(count);     System.out.println("max is: " + max);     System.out.println("min is: " + min);     System.out.println("Max Count is: " + maxCount);     System.out.println("Min Count is: " + minCount);      if (maxCount == minCount &amp;&amp; count &gt;= 1) {         status = true;     }      return status; } }
102926
Searching for " should return a list of questions that have the tag [comments] but not the tag [feature-request]. The right hand sidebar says that, but the search results are identical to .    As random points out, the operator works, but seems to be broken if a minus sign is the first tag in the resulting search URL. This is a problem because the system re-orders the tags when you put them into the search box, always putting the one with the minus sign first.    Edit: Here's another behaviour that I haven't encountered until now. I was trying to pattern search for tags that contain 'array' but NOT include '-array', so I did the search . The resulting page shows the right tags with the right operators on them, but the results aren't being filtered properly (the first result includes [multidimensional-array]). So I simplified and  (1,960 results), and then  (1,963 results -- what??), which still included that first question with [multidimensional-array] on it. Something is not working right here.
87827
I created a utility function to return the expected single item from an generator expression  print one(name for name in ('bob','fred') if name=='bob')   Is this a good way to go about it?  def one(g):     try:         val = g.next()         try:             g.next()         except StopIteration:             return val         else:             raise Exception('Too many values')     except StopIteration:         raise Exception('No values')
123088
I am writing a SQL query creator using some parameters. In Java, it's very easy to detect the last element of an array from inside the for loop by just checking the current array position with the array length.  for(int i=0; i&lt; arr.length;i++){      boolean isLastElem = i== (arr.length -1) ? true : false;         }   In PHP they have non-integer indexes to access arrays. So you must iterate over an array using a foreach loop. This becomes problematic when you need to take some decision (in my case to append or/and parameter while building query).   I am sure there must be some standard way of doing this.   How do you solve this in PHP?
129
What are Null Pointer Exceptions (java.lang.NullPointerException) and what causes them?  What methods/tools can be used to determine the cause so that you stop the exception from causing the program to terminate prematurely?
65647
Pattern pattern = Pattern.compile("^[a-z]+$"); String string = "abc-def"; assertTrue( pattern.matcher(string).matches() ); // obviously fails   Is it possible to have the character class match a "-" ?
31102
The example below throws an InvalidOperationException, "Collection was modified; enumeration operation may not execute." when executing the code.   var urls = new List&lt;string&gt;(); urls.Add("http://www.google.com");  foreach (string url in urls) {     // Get all links from the url     List&lt;string&gt; newUrls = GetLinks(url);      urls.AddRange(newUrls); // &lt;-- This is really the problematic row, adding values to the collection I'm looping }   How can I rewrite this in a better way? I'm guessing a recursive solution?
24654
Is there any performance difference between these two queries?  select name from Account where id = :myId  select name from Account where id = :myId limit 1   Or, I guess more general: does salesforce stop searching after first hit when there's a unique value as a condition?
117983
I am trying to remove duplicate and creating a set and list with non duplicate values related to field ord__c . Trying to minimize the code as far as possible. Let me know if I can handle the same using the below piece of code I am using :   Set &lt; Id &gt; OrId = new Set &lt; Id &gt; ();  Integer j = 0;         while (j &lt; ListR.size())         {           OrId.add(ListR.get(j).Ord__c);           if(OrId.contains(ListR.get(j).Ord__c))           {             ListR.remove(j);           }           else           {             j++;           }         }
78
We all know you can't do the following because of ConcurrentModificationException:  for (Object i : l) {     if (condition(i)) {         l.remove(i);     } }   But this apparently works sometimes, but not always. Here's some specific code:  public static void main(String[] args) {     Collection&lt;Integer&gt; l = new ArrayList&lt;&gt;();      for (int i = 0; i &lt; 10; ++i) {         l.add(4);         l.add(5);         l.add(6);     }      for (int i : l) {         if (i == 5) {             l.remove(i);         }     }      System.out.println(l); }   This, of course, results in:  Exception in thread "main" java.util.ConcurrentModificationException   Even though multiple threads aren't doing it. Anyway.  What's the best solution to this problem? How can I remove an item from the collection in a loop without throwing this exception?  I'm also using an arbitrary Collection here, not necessarily an ArrayList, so you can't rely on get.
63512
Am not doing anything fancy, just trying to use  method of list.      List&lt;Id&gt; myIdList = new List&lt;Id&gt;(); myIdList.add('0060E000008PdMk');  Id oppId ='0060E000008PdMk';      System.debug(myIdList.contains(oppId)); //Returns false   To my surprise, I spent a few hours debugging and came with this problematic code. Are we not supposed to use contains for List&lt;Id&gt; ?  Changing the type from List&lt;Id&gt; to List&lt;String&gt; makes my code run, but I dont have any clue why it does?   Can anyone shed some light?  UPDATE : As per the suggestion of sfdcfox I have raised a case with SF support. Case number "19522568". I will keep you guys updated with the results.  UPDATE 2 : Salesforce reached out to me for this,   A bug W-4884673 already exist for this issue. SF R&amp;D team is working on the same. Known issue link for reference:   There isn't any ETA for this to be fixed, so the case will be closed as "bug fix submitted"  UPDATE 3 : This has now been resolved
43217
Where is the mistake? $$-1=(-1)^{2/2}=\left(\left (-1\right)\displaystyle ^2\right)^{1/2}=1^{1/2}=\sqrt 1=1$$
107220
I have a map. the string is the label of a field of an object and the integer is the value that must go into this field of that object. But i don't know how to retrieve the API name of those fields from their labels. Please help!  Thanks in advance!
106280
Object o = new Long[0] System.out.println( o.getClass().isArray() ) System.out.println( o.getClass().getName() ) Class ofArray = ???   Running the first 3 lines emits;  true [Ljava.lang.Long;   How do I get ??? to be type long?   I could parse the string and do a Class.forname(), but thats grotty.   What's the easy way?