lundi 13 avril 2020

I can't "if" a string after a split in java [duplicate]

I have a String with 3 words and I want to run a block of code depending on the first word, so first I created a array and stored the values using "split()":

   String text = "Text1 Text2";
   String[] array = text.split(" ");

then, i did the comparison:

    if(array[0]=="Text1"){
        System.out.println("Hi");
    }else{
        System.out.println(">"+t1+"<");
    }

But instead of "Hi" it prints:

>Text1<

Any ideas?

edit: I also Tried storing the "array[0]" in a variable:

String t1 = array[0];
if(t1=="Text1"){
    System.out.println("Hi");
}

And nothing

Aucun commentaire:

Enregistrer un commentaire