+ 2
Changing text of String (Java)
Hi, in this code i want to change my String but couldn't. Can someone help me https://code.sololearn.com/cN8OnHv9CEP0/?ref=app
3 Respuestas
+ 5
For String types using == will return true if both Strings are the same object instance, where using the equals() method will return true if they both have the same value.
FYI, newer versions of Java allow for a String type to be used with a switch. So, you could use this instead of if-else if statements checking for equality.
switch(anji) {
case "A1":
bag[0] = "o";
break;
case "A2":
bag[1] = "o";
break;
case "A3":
bag[2] = "o";
break;
case "A4":
bag[3] = "o";
break;
case "A5":
bag[4] = "o";
break;
}
0
Ow it worked using equal method, but then i'm curious. Why should i use the equal method, can you explain?