There is a User object, and from the given collection you want to output all the numbers. In order to compare the uniqueness of the number. The data can be output to the console. But it cannot be added to the ArrayList.
public DatabaseReference databaseReference;
ArrayList<String> codesOfUsers = new ArrayList<>();
databaseReference = FirebaseDatabase.getInstance().getReference().child("User");
ChildEventListener сhildEventListener = new ChildEventListener() {
@Override
public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
String number = snapshot.child("number").getValue(String.class);
codesOfUsers.add(number);
System.out.println(number);
}
@Override
public void onChildChanged(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
}
@Override
public void onChildRemoved(@NonNull DataSnapshot snapshot) {
}
@Override
public void onChildMoved(@NonNull DataSnapshot snapshot, @Nullable String previousChildName) {
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
Log.e("The read failed: " ,error.getMessage());
}
};
databaseReference.addChildEventListener(сhildEventListener);
System.out.println("Output" + codesOfUsers.toString());