Netbeans does not recognize ArrayUtil

I use the following instruction

int[] numList = ArrayUtil.randomIntArray(100, 100);

and i imported

import java.util.*;

therefore, importing the correct class is out of the question here. I'm trying to create an array of 100 numbers and fill the array with random numbers from 1-100, but netbeans places the red line under "ArrayUtil", I look through it with the mouse to read the error, "cannot find the symbol, Symbol: variable ArrayUtil" why this happens when i imported all the necessary classes

thank

+3
source share
2 answers

You need to download and import Apache Commons if you want to use your libraries. It is not part of the standard Java API.

Or create a function yourself;

public int[] randomIntArray(int length, int size) {
  Random r = new Random();
  int[] numbers = new int[length];
  for(int i = 0; i < length; i++) {
    numbers[i] = r.nextInt(size+1);
  }
  return numbers;
}
+6

2.3

+5

All Articles