Just comparing some behaviors accross different languages and in java (java 8) I have tried something and I got weird results:
here I iterate over a small String array, and display the iterator along with the value (nothing fancy, we agree...). however when I change in the sysout concatenation between single quote ' ' and double quote " " the behavior is completely different. 1- displays the end result of the iteration (3 as I increment through the loop) and it seems that it calculates + 1 from the last iteration so in this case the end result is:
33Foo 34Bar 35Baz
public static void main(String[] args) {
int y = 0;
String[] arr= {"Foo", "Bar", "Baz"};
for(int i = 0; i < arr.length; i++) {
y++;
System.out.println(y +' '+ arr[i]);
}
}
while changing the above to double quotes:
public static void main(String[] args) {
int y = 0;
String[] arr= {"Foo", "Bar", "Baz"};
for(int i = 0; i < arr.length; i++) {
y++;
System.out.println(y +" "+ arr[i]);
}
}
will have the expected result:
1 Foo 2 Bar 3 Baz
Anyone knows why? Just interested to know the reason of the impact using single vs double quote...