-1
package test;

import java.io.Console;

public class Test 
{
    public static void main(String[] args)
    {
        Console console=System.console();

        char[] psw=console.readPassword("Enter Password");  // Reading Password
        char[] pswd={'a'};    // Variable to compare password entered

        System.out.println(psw);

        if(psw.equals(pswd))  // Here i do not understand how to verify password correctly?
        {
            System.out.println("Ok");
        }
    }
}

I wish to use the Console class correctly but i am unable to do so. Kindly correct the code if you understand my mistakes.

Bohuslav Burghardt
  • 33,626
  • 7
  • 114
  • 109
ema
  • 79
  • 1
  • 1
  • 8

1 Answers1

1

Use Arrays.equals(), which actually compares the contents of both arrays:

if (Arrays.equals(psw, pswd)) {}

Refer to this SO post for more details.

Community
  • 1
  • 1
Bohuslav Burghardt
  • 33,626
  • 7
  • 114
  • 109