Comparison of data after nextLine java [duplicate]

-2

I'm not able to make my verification structure work, I can not get past typing stop, display the message, and the program continues loop .

/ *      * To change this license header, choose License Headers in Project Properties.      * To change this template file, choose Tools | Templates      * and open the template in the editor.      * /     package javaapplication4;

/**
 *
 * @author Deny
 */
import java.util.Scanner;

public class JavaApplication4 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
       String resposta;
       String r;
       String respostaVerificadora;
       String[] camgirls = new String[50000];
       Scanner scan = new Scanner(System.in);

       //cadastro de cam girls
       for(int c=0; c < 50000; c++) {
           System.out.println("Digite o nome da camgirl de numero: "+c);
          //ISSO AQUI NAO TA FUNCIONANDO EU DIGITO PARE AQUI
           resposta = scan.next();
           //PARA DAR IGUAL AQUI
           respostaVerificadora = "pare";
     //E NA HORA DE VERIFICAR QUE OS DOIS SAO IGUAIS, O JAVA NAO RECONHECE E NAO ENTRA NO IF
           if(resposta == respostaVerificadora ) {
               System.out.println("parei");
               break;
           }

       }
        System.out.println("PROGRAMA FINALIZADO");
    }

}
    
asked by anonymous 31.10.2018 / 21:10

1 answer

0

Java has no operator overhead, when you compare objects using == , Java compares the reference of these objects. Even if the value of the strings are equal, the references are different, to compare the values you need to use the equals method.

resposta.equals(respostaVerificadora)

I also suggest you try to learn how to use the Java List, because creating 50,000 variable arrays is absurdly inefficient.

    
31.10.2018 / 21:28