Check out example codes for "Sort Firebase database android". It will help you in understanding the concepts better.

Code Example 1

Query query = FirebaseDatabase.getInstance()
        .getReference()
        .child("chats")
        .limitToLast(50);

Learn ReactJs, React Native from akashmittal.com