Hi all,
Pls check the below question .
public class Friends {
public static void main(
String[] args) {
// First set
int index1 = 2;
String[] friends1 = {"Micky","Pluto","Donald"};
String str1 = friends1[--index1] = friends1[--index1]+ " is my best friend.";
System.out.println("str1="+str1);
// Second set
int index2 = 2;
String[] friends2 = {"Micky","Pluto","Donald"};
String str2 = friends2[--index2] += " is my best friend.";
System.out.println("str2="+str2);
}
}
The output is :
str1=Micky is my best friend.
str2=Pluto is my best friend.
Can somebody pls explain me why the output is so diffent with str1 and str2 eventhough we are doing same operation.
From my understanding if we declare like below if we declare int i=5,
then i+=5 and i=i+5 are same with only one exception that i+=5 will do implicity convertion like i=(int)i+5
Thanks in advances
Cheers
Raju