jeudi 9 juillet 2020

Substring in if statement [duplicate]

Can someone explain to me why the following code as shown doesn't display "IS equal", but if I change the assignment to ip to the commented one it does?

public class cl {

    public static void main(String[] args) {
        String temp = null;
        String a = null;
        String b = null;
        String ip = null;

        ip = "DateTime  ";
//      ip = "DateTime";
        b =  "DateTime";

        a = ip.substring(0, 8);

        if (a == b) {
            System.out.println("IS equal");
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire