karen66
karen66

Reputation: 33

Eclipse Import - java Collections can not be resolved error

Error happens in the code below.

Arrays.sort(a, Collections.reverseOrder());

It says "Collections can not be resolved."

Attempts to solve:

(1) Added the import at the top, but it still says "import java.util.Collections can not be resolved."

import java.util.Collections;

(2) Collection import works fine though

import java.util.Collection;

Any help will be appreciated.

Upvotes: 0

Views: 5801

Answers (3)

Viktor Puglejev
Viktor Puglejev

Reputation: 9

Delete all imports that you have and press CTRl+Shift+O It will re-import everything you need Solved the same issue for me

Upvotes: 0

user14972917
user14972917

Reputation:

For me the "solution" was to add an "additional" JRE (Window > Preferences > Java > Installed JREs > Add) in Eclipse (version 2021-06, 4.20.0) and switch to that.

In Linux you can just add e.g. /usr/lib/jvm/java-11-openjdk-amd64 and additionally /usr/lib/jvm/java-1.11.0-openjdk-amd64.

Switching back to the JRE where Eclipse showed the errors was also fine. The error message stayed away.

Upvotes: 1

Atmas
Atmas

Reputation: 2393

Ensure you are not somehow referencing or implicitly using a Java Runtime that's older than Collections allow.

Upvotes: -1

Related Questions