title: ANDROID: If...Else as Switch on String
body: <p>I'm writing an Android app for work that shows the status of our phone lines, but thats neither here nor there.</p>
  
  <p>I make a call to one of our servers and get returned JSON text of the status. I then parse this putting each line into a SortedMap (TreeMap) with the Key being the name of the line and my own class as the value (which holds status and other details).</p>
  
  <p>This all works fine.</p>
  
  <p>When the app runs it should then show each line and the info I have retrieved, but nothing gets updated.</p>
  
  <p>The JSON is returned and added to the Map correctly.</p>
  
  <p>This is a snapshot of the code that isn't working. I simply iterate through the map and depending on the value of key update the relevant TextView. The problem I am having is that when it gets to the IF statement that matches it never runs that code. It skips it as if values don't match.</p>
  
  <p>I can't see any errors. Is this the only way to do this as I know you can't use Switch..Case etc?</p>
  
  <p>Can anyone see my error? I've been coding on Android for 1 week now so its probably a newbie error!!</p>
  
  <p>Thanks
  Neil</p>
  
  <pre><code>Iterator iterator = mapLines.entrySet().iterator();
  
  while(iterator.hasNext())
  {
  // key=value separator this by Map.Entry to get key and value
  Map.Entry&lt;String, Status&gt; mapEntry = (Map.Entry&lt;String, Status&gt;)iterator.next();
  
  // getKey is used to get key of Map
  String key = (String)mapEntry.getKey();
  
  // getValue is used to get value of key in Map
  Status value = (Status)mapEntry.getValue();
  
  if(key == "Ski")
  {
      TextView tvStatus = (TextView)findViewById(R.id.SkiStatus);
  
      tvStatus.setText(value.Status);
  }
  else if(key == "Cruise")
  {
      TextView tvStatus = (TextView)findViewById(R.id.CruiseStatus);
  
      tvStatus.setText(value.Status);
  }
  else if(key == "Villas")
  {
      TextView tvStatus = (TextView)findViewById(R.id.VillasStatus);
  
      tvStatus.setText(value.Status);
  }
  }
  </code></pre>