0
FirebaseDatabase db =FirebaseDatabase.getInstance();
DatabaseReference node = db.getReference("plantation");

.....

reference.child(String.valueOf(maxid+1)).setValue(obj);

as you can see the reference id starts from the value of "maxid" which is int, is there a way if can have id's like : DL00001

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
  • The keys are always Strings. Would you like to sequential node keys? – Alex Mamo May 29 '21 at 11:56
  • 1
    Welcome to SO. You are free to use any string as a key, but as @AlexMamo states, they are always strings. If you want them to look something sequential like DL0001, DL0002 etc you could read them in as a string, cast the numeric part to an int, increment and then write them back out as a string; DL00002. HOWEVER, this is probably a bad idea. You are generally way better off letting Firebase create it's own node keys and then use a child node for ordering, if that's what you're after. We would really need more info as to *why* you want to do this to provide any concrete answer though. – Jay May 29 '21 at 13:42
  • 2
    For more on why this is an antipattern in Firebase: [Best Practices: Arrays in Firebase](https://firebase.googleblog.com/2014/04/best-practices-arrays-in-firebase.html) and [How to create auto incremented key in Firebase?](https://stackoverflow.com/questions/39519021/how-to-create-auto-incremented-key-in-firebase) – Frank van Puffelen May 29 '21 at 15:12

0 Answers0