Home > other >  How to import org.apache.commons.collections4
How to import org.apache.commons.collections4

Time:08-10

I would like to use

CollectionUtils.isEmpty

function in my spring mvc project. To do that I added following block to my pom.xml file:

<dependency>
        <groupId>org.apache.commons</groupId>
        <artifactId>commons-collections4</artifactId>
        <version>4.4</version>
</dependency>

and my java class is:

import org.apache.commons.collections4;
public class main {
    public static void main(String[] args) {
        List<Integer> empty_list = new ArrayList<Integer>();
        if (CollectionUtils.isEmpty(empty_list)) {
            System.out.println("List is empty");
        }
    }
}

When I run the code, I got the following error:

java: package org.apache.commons.collections4 does not exist

It is already in my pom.xml file, what should I do to solve this problem?

CodePudding user response:

You should fix import for CollectionUtils

import org.apache.commons.collections4.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

public class main {
    public static void main(String[] args) {
        List<Integer> empty_list = new ArrayList<Integer>();
        if (CollectionUtils.isEmpty(empty_list)) {
            System.out.println("List is empty");
        }
    }
}

CodePudding user response:

if you use IntelliJ IDEA - JetBrains. you should do this.

  1. In the Maven tool window, right-click a linked project.
  2. From the context menu, select Reload project .

CodePudding user response:

I guess there are no sync dependencies.

  • Related