Firebase database value keeps changing instead of adding itself

Firebase database value keeps changing instead of adding itself

What I want to do is to first check whether there's a value in my Firebase database, if there isn't then add it. My database looks like this:

What I want to do is to first check whether there's a value in my Firebase database, if there isn't then add it. My database looks like this:

appnickname{
Strings{
    key : value
    key : value
    key : value

And my current code is this:

refference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            for (DataSnapshot n : dataSnapshot.getChildren()) {
                if (n.getValue().equals(string)) {
                    break;
                }
                refference.child("key").setValue(string);
            }
        }

    @Override
    public void onCancelled(@NonNull DatabaseError databaseError) {
    }
});

The problem with my current code is that it simply changes the string that exists under the same key instead of adding a new key/value combo. The good thing is that if it's the same value, nothing happens as far as I can see. How can I fix the bad thing?

java firebase loops

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Introduction to Loops in Java | Java Loops Beginners | Java Training

Introduction to Loops in Java | Java Loops For Beginners | Java Training

Java Core (2020) | Java for beginners | Brush up your Java Skills | Get Hired

In this video we will learn about all the major concepts that come under Java Core . The course is very carefully designed and is made with keeping simplicit...

Loops in Java For While Do While Loops Java Course Using Different Types of Java Loops

Loops in Java | For, While, Do While Loops | Java Course | Using Different Types of Java Loops. We will see How to use Different Types of Java Loops in Java like For, While, Do While Loops with example. Java is a widely used robust technol...

Anatomy of Sequential Data Processing With Java Streams

It takes an array of integers as a parameter, and very simply sums all the values and returns the sum. We can use recursion for this.

Java Fundamentals: Learn Java for absolute beginners |Simpliv

Java Fundamentals: Learn Java for absolute beginners