David Bowen David Bowen - 3 years ago 235
Java Question

Firebase check value

in my firebase database I would like to check whether the "read" key is equalled to "false" However, the if statement below does not seem to work.

ValueEventListener eventListener = new ValueEventListener() {
public void onDataChange(DataSnapshot dataSnapshot) {
String true3 = "true";
for(DataSnapshot ds : dataSnapshot.getChildren()) {

if( ( ds.child("read").getValue() == ("false"))){


public void onCancelled(DatabaseError databaseError) {}

Answer Source

ds.child("read").getValue() will return an Object and obj == "false" will compare reference not their values so use snapshot#getValue(ClassName.class)

  // and always compare String objects with String#equals

instead of

  if( ( ds.child("read").getValue() == ("false"))){
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download