According to your problem you could use this:
For Android:
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef = database.getReference("posts");
String key = myRef.push().getKey(); //this returns the unique key generated by firebase
myRef.child(key).child("author").setValue("gracehop");//this creates the reqs key-value pair
myRef.child(key).child("title").setValue("Announcing COBOL");//this creates the reqs key-value pair
For Web Dev:
var messageListRef = firebase.database().ref('posts');
var newMessageRef = messageListRef.push();
newMessageRef.set({
'author': 'gracehop',
'title': 'Announcing COBOL'
});