title: Append a string to a list on Firebase Realtime Database
body: <p>I want to append a String to my List on the Firebase Realtime Database.
  (My code already works but there is a problem)</p>
  
  <p>So the Database looks like this:</p>
  
  <pre><code>message:
      0: "some string"
      1: "another string"
      2: "some string"
  </code></pre>
  
  <p>But I think the problem with this code would be, that if somebody reads the numbers of messages and then wants to write a message there would be a problem, when another user writes a message in the mean time (because the number of messages would change).</p>
  
  <pre><code>FirebaseDatabase database = FirebaseDatabase.getInstance();
  final DatabaseReference myRef = database.getReference("message");
  
  myRef.addListenerForSingleValueEvent(new ValueEventListener() {
      @Override
      public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
          myRef.child(
              String.valueOf(dataSnapshot.getChildrenCount())
              ).setValue("SOME STRING");
      }
  
      @Override
      public void onCancelled(@NonNull DatabaseError databaseError) {
  
      }
  });
  </code></pre>