Java comparing strings -


this question has answer here:

i have small of problem. have string lists same size , string compare. meaning want compare string first list index of compared string in list , string other list on index.

private string getstringonindex(list<string> list1, list<string> list2,string elem)  {                 string elem2;          (int = 0; i<list1.size();i++) {              if(list1.get(i).equals(elem)){                 elem2 = list2.get(i);                 return elem2;              } else {                 return "nope";             }         }  } 

is wrong compare 2 strings that. or should use operator ==. know style string lists not nice temporary solution. thx :)

to answer specific question on "string comparison", doing correct. string content comparison should done using equals(). using operator == checking equality of reference, not content.

for work doing now, looks key-value lookup me. may consider redesign and, instead of storing 2 lists, make map<string, string>


Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -