![Mastering Firebase for Android Development](https://wfqqreader-1252317822.image.myqcloud.com/cover/713/36699713/b_36699713.jpg)
上QQ阅读APP看书,第一时间看更新
Writing HashMaps to Realtime Database
By using the updateChildren() method of the database reference class, we can write the HashMap data structure into Firebase Realtime Database. Let's create a HashMap and add different key-value pairs, each should be reflected in the Realtime Database:
// Write a message to the database
mDatabase = FirebaseDatabase.getInstance();
mDbRef = mDatabase.getReference("Donor/Name");
//Writing Hashmap
Map<String, Object> mHashmap = new HashMap<>();
mHashmap.put("Name 1/title", "Ashok");
mHashmap.put("Name 1/content", "Parinitha");
mHashmap.put("Name 2/title", "Krishna");
mHashmap.put("Name 2/content", "Sumuthra");
mDbRef.updateChildren(mHashmap);
The following screenshot illustrates the HashMap writing in the Firebase console:
![](https://epubservercos.yuewen.com/E46BFC/19470391708875606/epubprivate/OEBPS/Images/Chapter_59.jpg?sign=1739253187-hawDQwnipbOlU4ByPrwgCEKFfhQvLtDt-0-c1e809944c9c84f9f44a9e6ace0607bf)