Hello, tell me how can I compare 2 arrays? There is a code, in it 2 identical array, 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 ("Password is correct");
ELSE {
System.out.PrintLN ("Wrong Password");
}
for (int i = 0; i & lt; args.length; i ++)
System.Out.print (Args [i]);
System.Out.printLN ();
For (int i = 0; i & lt; password.length; i ++)
System.out.print (Password [i]);
}
}
Answer 1, Authority 100%
array1.equals (array2)
the 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)) {...