I have a firebase database consisting of a bunch of cases. I want to loop through all these cases and find the count of Male cases only, male is represented by "M".
How I am trying to query for this data:
databseCOVIDCases = FirebaseDatabase.getInstance().getReference();
databseCOVIDCases.addValueEventListener(new ValueEventListener() {
   @Override
   public void onDataChange(@NonNull DataSnapshot snapshot) {
       for (DataSnapshot data : snapshot.getChildren()) {
           if (data.child("Sex").getValue(String.class) == "M") {
               numMaleCases++;
           }
       }
   }
   @Override
   public void onCancelled(@NonNull DatabaseError error) { }
});
When I set the text of the text view it shows 0 and then crashes with an out of memory error.

 
    