Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method join (String, List<String>) is undefined for the type String [closed]

Tags:

java

string

I'm learning Java and I have come across one tutorial about Hash Maps and start typing the same code like my tutor. The problem is when I came across String.join method, I got an error and my tutor didn't, and I do not know why.

This is the error:

The method join(String, List<String>) is undefined for the 
type String

Can you tell me whats the problem?

private String getZnanjaList(){

    List <String> listaZnanja = new ArrayList<>();

    for (String znanje : this.znanja.keySet()){
        listaZnanja.add(znanje + ": " + this.znanja.get(znanje));
    }

    return String.join("; ", listaZnanja);
}
like image 470
taga Avatar asked Feb 24 '26 06:02

taga


1 Answers

When you turn to the javadoc for String.join() you find:

public static String join(CharSequence delimiter,
                          Iterable<? extends CharSequence> elements)
Returns a new String composed of copies of the CharSequence elements joined together with a copy of the specified delimiter.
...
Since:
1.8

That is all there is to this: you must be using an older version of Java.

So: you should check what JDK version is available on your system (respectively used when you invoke javac, or what your IDE points to), and either restrict yourself to things that work with that version, or (recommended) directly hop to Java 8, or Java 11.

like image 113
GhostCat Avatar answered Feb 26 '26 21:02

GhostCat



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!