Setting custom key when pushing new data to firebase database

Well, I am new to Firebase and I want to have my own keys while pushing new data to database.

Problem:

FireBase.push().setValue(mapped_values);

This gives structure like below:

 database output

How can I create my own custom key there? Such as username or something.


Calling push() will generate a key for you.

If instead you use child(), you can determine they key/path yourself.

ref.child("Victor").setValue("setting custom key when pushing new data to firebase database");

        String key="1234567sdfsf8";
        //custom object
        User user=new User();
        DatabaseReference mDatabase;
        mDatabase = FirebaseDatabase.getInstance().getReference();
        mDatabase.child("Users").child(key).setValue(user);