Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import org.apache.commons.collections4

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?

like image 712
Alex.m Avatar asked Aug 19 '26 18:08

Alex.m


1 Answers

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");
        }
    }
}
like image 132
Roman Cherepanov Avatar answered Aug 22 '26 07:08

Roman Cherepanov