'How to get data into an Arraylist in a collection in the Firestore Database?

i m using cloud firestore database and i have an collection which is named Jobpost1. i want to get data from this collection and store in arraylist.

my java code

List<Jobpost> mList = new ArrayList<>();  //this is my arraylist
private CollectionReference collectionReference=db.collection("Job Post1");

 @Override
    public void onStart() {
        super.onStart();

        collectionReference.get()
                .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                    @Override
                    public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                        if (!queryDocumentSnapshots.isEmpty()){
                            for (QueryDocumentSnapshot journals: queryDocumentSnapshots){

                            }

                        }else {

                            noJournalEntry.setVisibility(View.VISIBLE);

                        }
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {

                    }
                });

    }

database



Solution 1:[1]

You can populate list this way

    List<Jobpost> mList = new ArrayList<>();  //this is my arraylist
    private CollectionReference collectionReference=db.collection("Job Post1");

    @Override
    public void onStart() {
        super.onStart();

        collectionReference.get()
                .addOnSuccessListener(new OnSuccessListener<QuerySnapshot>() {
                    @Override
                    public void onSuccess(QuerySnapshot queryDocumentSnapshots) {
                        if (!queryDocumentSnapshots.isEmpty()){
                            for (QueryDocumentSnapshot journals: queryDocumentSnapshots){
                                 JobPost jobPost= journals.toObject(JobPost.class);
                                 mList.add(jobPost);
                            }
                        }else {
                            noJournalEntry.setVisibility(View.VISIBLE);
                        }
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {

                    }
                });

    }

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 JunaidKhan