count the number of times data apears in firebase database code example

Example: count the number of times data apears in firebase database

databaseReference = FirebaseDatabase.getInstance().getReference().child("Attendance").child(istrustnumberavailable);
    databaseReference.limitToFirst(5);

    Query query = databaseReference.orderByChild("name").equalTo("prof");

    ChildEventListener removedListener = query.addChildEventListener(new ChildEventListener() {
        @Override
        public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

            if (dataSnapshot.exists()){

              long  count=  dataSnapshot.getChildrenCount();


            }


        }

        @Override
        public void onChildChanged(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {

            if (dataSnapshot.exists()){

                long  count=  dataSnapshot.getChildrenCount();


            }


        }

        @Override
        public void onChildRemoved(@NonNull DataSnapshot dataSnapshot) {

            if (dataSnapshot.exists()){

                long  count=  dataSnapshot.getChildrenCount();


            }



        }

        @Override
        public void onChildMoved(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {


        }

        @Override
        public void onCancelled(@NonNull DatabaseError databaseError) {

        }
    });