I want to upload data like this:

Edited Questions
//I have ArrayList<FoodModel> arr;
ArrayList<FoodModel> arr = new ArrayList<>();
arr.add(new FoodModel("Hamburger"));
arr.add(new FoodModel("Pizza"));
arr.add(new FoodModel("Chicken"));
//and so on...
I want to upload that ArrayList to firestore it is Possible?
You just need add a list field in the hashmap:
Map<String, Object> docData = new HashMap<>();
docData.put("favFoods", Arrays.asList("Hamburger", "Vegetables"));
db.collection("data").document("one")
.set(docData)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Log.d(TAG, "DocumentSnapshot successfully written!");
}
})
.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
Log.w(TAG, "Error writing document", e);
}
});
Alternatively, you can also use arrayUnion to add new items to an array.
DocumentReference docRef = db.collection("col").document("docId");
docRef.update("favFoods", FieldValue.arrayUnion("Pizza"));
You can add array of objects (and even nested maps) in Firestore. However, you should add the array as a list.
References:
Cloud Firestore Data Types
Update elements in an array
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With