How do I get the size of a Java String?

Asked

Viewed 2,019 times

1

I’m creating a fake bank in java but I don’t know how to check if the password has 8 characters.

public void criarSenha(){
 String senhacriada = (JOptionPane.showInputDialog("Qual a senha ?"));
       if(tamanhodasenhacriada >= 8) {       //! O problema está aqui !
   System.out.println("Senha criada com sucesso !"); 
 }else {
   System.err.println("senha >= 8 !"); 
 }
}

How do I find the size of the string ?

In javascript i do :

if(lenght(senha) >= 8){
// Codigo
}

But in Java I don’t know because I’m starting to learn !

  • 1

    A tip for you who is starting: when you do not know the functioning of some class, I suggest looking for the documentation of the same.

  • 1

    Thanks for the tip @nullptr !

1 answer

7


Browser other questions tagged

You are not signed in. Login or sign up in order to post.