<<< Relational Operators and Arrays | Index | Arrays.sort >>> |
Code that uses the equals method
String[] titles1 = { "War and Peace", "Gone With the Wind"}; String[] titles2 = { "War and Peace", "Gone With the Wind"}; if (titles1 == titles2) System.out.println("titles1 == titles2 is true"); else System.out.println("titles1 == titles2 is false"); if (Arrays.equals(titles1, titles2)) System.out.println( "Arrays.equals(titles1, titles2) is true"); else System.out.println( "Arrays.equals(titles1, titles2) is false");
The console output
titles1 == titles2 is false Arrays.equals(titles1, titles2) is true
<<< Relational Operators and Arrays | Index | Arrays.sort >>> |