-2

I have a code to take the value from the table, but when I place it in a condition, I will get the wrong answer

jenis_absen = cursor.getString(9);
System.out.println("jenis absen >>" + jenis_absen);
System.out.println("cursor >>" + cursor.getString(9));
if (jenis_absen == "1"){
     System.out.println(">>>>> TRUE");
 }
 else{
      System.out.println(">>> FALSE");
 }

enter image description here

this is the output

enter image description here

Markus Kauppinen
  • 2,851
  • 4
  • 17
  • 28
Firuma
  • 105
  • 12

1 Answers1

1

Try this

jenis_absen = cursor.getString(9);
System.out.println("jenis absen >>" + jenis_absen);
System.out.println("cursor >>" + cursor.getString(9));
if (jenis_absen.equals("1")){
     System.out.println(">>>>> TRUE");
 }
 else{
      System.out.println(">>> FALSE");
 }

== compares the reference of the String, if both the String references are same then it will be true but .equals() compares the value inside String.

theanilpaudel
  • 3,160
  • 8
  • 34
  • 59