Hello, tell me how you can compare 2 arrays? There is a code, in it 2 identical arrays, but the condition does not pass.

package VarA; public class Task4 { public static void main(String[] args){ String[] password = {"q", "w", "e", "r", "t", "y"}; if(args.equals(password)) System.out.println("Пароль верный"); else { System.out.println("Пароль неверный"); } for(int i = 0; i < args.length; i++) System.out.print(args[i]); System.out.println(); for(int i = 0; i < password.length; i++) System.out.print(password[i]); } } 

    1 answer 1

    array1.equals(array2) same as array1 == array2 , addresses are compared, not content.

    You need to use Arrays.equals (array1, array2) for comparison, i.e.

     if(Arrays.equals(args, password)) {...