When validating a tag, the string [duplicate] does not match

2

I have this code to write a xml but when validating the statement if does not take it into account. Does anyone know why?

How to validate a xml: tag

for(int i=0; i<nodeList.size(); i++){
    if(nodeList.get(i).toString() == "</cfdi:Comprobante>"){
        System.out.println("hola");
    }
}
    
asked by Nov Esk Eduard 08.06.2017 в 18:49
source

1 answer

1

To compare strings we use the equals () , You should not use the operator == .

Therefore this should should do the job correctly:

  if(nodeList.get(i).toString().equals("</cfdi:Comprobante>")){
            System.out.println("hola");
  }
    
answered by 08.06.2017 / 18:55
source