Comparing strings

In code while we create HashMap class in lection “Collisions: Looping Java” why we use == to compare 2 strings instead of .equals() for if(current.key == key) instead of using if(current.key.equals(key)) ?
Key is string so we need to compare values of string not reference.

public void assign(String key, String value) {
        int arrayIndex = this.hash(key);
        LinkedList list = this.hashmap[arrayIndex];
        if (list.head == null) {
            list.addToHead(key, value);
        Node current = list.head;
        while(current != null){
          if(current.key == key){
            current.setKeyValue(key, value);
          if(current.getNextNode() == null){
            current.setNextNode(new Node(key,value));
          current = current.getNextNode();

Link to lection:

I think that
is better than
current.key == key
just to be safe.

I don’t think it is about safe or better, but true or false.

In java Strings are class and every String variable have reference to String object.
When we use == for 2 String variable we are comparing their memory location of objects, and since String are immutable every String variable have its own object with different mem location even if they have same value so that is why we use .equals() to compare actual values of 2 String and not address.