Given code:
float [] f3 = {2.7f};
float [] [] f2 = {{42.0f}, {1.7f, 1.9f}};
What should I understand by statement if(f2[1]==f3)? The result is false, but are we comparing their sizes?
Given code:
float [] f3 = {2.7f};
float [] [] f2 = {{42.0f}, {1.7f, 1.9f}};
What should I understand by statement if(f2[1]==f3)? The result is false, but are we comparing their sizes?
You are comparing references, because in Java arrays are objects:
Since these are different objects, you will get false.
If you had this:
int[] f3 = { 100 };
int[][] f2 = { f3, { 2, 1 } };
System.out.println(f2[0] == f3);
The output would be true because you are adding the reference f3 as an element of the array f2.
f2[1] == f3 compares references to different float[] instances and it will never return true. Use Arrays.equals instead