error: no suitable method found for toArray(int[])
         return intList.toArray(new int[intList.size()]);
                       ^
    method Collection.<T#1>toArray(T#1[]) is not applicable
      (inference variable T#1 has incompatible bounds
        equality constraints: int
        upper bounds: Object)
    method List.<T#2>toArray(T#2[]) is not applicable
      (inference variable T#2 has incompatible bounds
        equality constraints: int
        upper bounds: Object)
    method AbstractCollection.<T#3>toArray(T#3[]) is not applicable
      (inference variable T#3 has incompatible bounds
        equality constraints: int
        upper bounds: Object)
    method ArrayList.<T#4>toArray(T#4[]) is not applicable
      (inference variable T#4 has incompatible bounds
        equality constraints: int
        upper bounds: Object)
  where T#1,T#2,T#3,T#4 are type-variables:
    T#1 extends Object declared in method <T#1>toArray(T#1[])
    T#2 extends Object declared in method <T#2>toArray(T#2[])
    T#3 extends Object declared in method <T#3>toArray(T#3[])
    T#4 extends Object declared in method <T#4>toArray(T#4[])
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

Tool completed with exit code 1















 import java.util.ArrayList;


                import java.util.Arrays;


                public class HashFunction2 {

                    int[] theArray;
                    int arraySize;
                    int itemsInArray = 0;

                    public static void main(String[] args) {

                        HashFunction2 theFunc = new HashFunction2(31);

                        int[] elementsToAdd2 = { 100, 510, 170, 214, 268, 398,
                                235, 802, 900, 723, 699, 1, 16, 999, 890,
                                725, 998, 978, 988, 990, 989, 984, 320, 321,
                                400, 415, 450, 50, 660, 624 };

                        // Demonstrate how data normally follows patterns and how
                        // a non-prime sized array can cause havoc

                        int[] elementsToAdd3 = { 30, 60, 90, 120, 150, 180,
                                210, 240, 270, 300, 330, 360, 390, 420, 450,
                                480, 510, 540, 570, 600, 989, 984, 320, 321,
                                400, 415, 450, 50, 660, 624 };

                        theFunc.hashFunction2(elementsToAdd2, theFunc.theArray);

                        // theFunc.modThirty();

                        theFunc.increaseArraySize(60);

                        theFunc.displayTheStack();

                        theFunc.fillArrayWithNeg1();

                        theFunc.doubleHashFunc(elementsToAdd2, theFunc.theArray);

                        theFunc.displayTheStack();

                        theFunc.findKeyDblHashed(990);

                    }

                    // Outputs the matches that would put an item in
                    // index 0 if arraySize was 31

                    public void modThirty() {

                        for (int i = 1; i < 999; i++) {

                            if (i % 30 == 0) {

                                System.out.println(i);

                            }

                        }

                    }

                    public boolean isPrime(int number) {

                        // Eliminate the need to check versus even numbers

                        if (number % 2 == 0)
                            return false;

                        // Check against all odd numbers

                        for (int i = 3; i * i <= number; i += 2) {

                            if (number % i == 0)
                                return false;

                        }

                        // If we make it here we know it is odd

                        return true;

                    }

                    // Receives a number and returns the next prime
                    // number that follows

                    public int getNextPrime(int minNumberToCheck) {

                        for (int i = minNumberToCheck; true; i++) {

                            if (isPrime(i))
                                return i;

                        }

                    }

                    // Increase array size to a prime number

                    public void increaseArraySize(int minArraySize) {

                        // Get a prime number bigger than the array
                        // requested

                        int newArraySize = getNextPrime(minArraySize);

                        // Move the array into a bigger array with the
                        // larger prime size

                        moveOldArray(newArraySize);

                    }

                    public void moveOldArray(int newArraySize) {

                        // Create an array that has all of the values of
                        // theArray, but no empty spaces

                        int[] cleanArray = removeEmptySpacesInArray(theArray);

                        // Increase the size for theArray

                        theArray = new int[newArraySize];

                        arraySize = newArraySize;

                        // Fill theArray with -1 in every space

                        fillArrayWithNeg1();

                        // Send the values previously in theArray into
                        // the new larger array

                        hashFunction2(cleanArray, theArray);

                    }

                    // Will remove all empty spaces in an array



                public int[] removeEmptySpacesInArray(int[] arrayToClean) { 


                         ArrayList<Integer> intList = new ArrayList<Integer>(); 


                        // Cycle through the array and if a space doesn't 


                         // contain -1, or isn't empty add it to the ArrayList 


                        for (int theint : arrayToClean) 


                            if (theint !=-1 && theint !=' ') 


                                 intList.add(theint); 


                         return intList.toArray(new int[intList.size()]); 

                     } 


                    public void doubleHashFunc(int[] stringsForArray, int[] theArray) {

                        for (int n = 0; n < stringsForArray.length; n++) {

                            // Store value in array index

                            int newElementVal = stringsForArray[n];

                            // Create an index to store the value in by taking
                            // the modulus

                            int arrayIndex = newElementVal % arraySize;

                            // Get the distance to skip down in the array
                            // after a collision occurs. We are doing this
                            // rather than just going to the next index to
                            // avoid creating clusters

                            int stepDistance = 7 - (newElementVal % 7);

                            System.out.println("step distance: " + stepDistance);


                             * System.out.println("Modulus Index= " + arrayIndex + " for value "
                             * + newElementVal);

                            // Cycle through the array until we find an empty space

                            while (theArray[arrayIndex] != -1) {

                                arrayIndex += stepDistance;

                                // System.out.println("Collision Try " + arrayIndex +
                                // " Instead");

                                // If we get to the end of the array go back to index 0

                                arrayIndex %= arraySize;

                            }

                            theArray[arrayIndex] = newElementVal;

                        }

                    }

                    // Returns the value stored in the Double Hashed Hash Table

                    public int findKeyDblHashed(int key) {

                        // Find the keys original hash key
                        int arrayIndexHash = key % arraySize;

                        // Find the keys original step distance


                        int stepDistance = 5 - (key % 5);

                        while (theArray[arrayIndexHash] != -1) {

                            if (theArray[arrayIndexHash] == key) {

                                // Found the key so return it
                                System.out.println(key + " was found in index "
                                        + arrayIndexHash);

                                return theArray[arrayIndexHash];

                            }

                            // Look in the next index

                            arrayIndexHash += stepDistance;

                            // If we get to the end of the array go back to index 0

                            arrayIndexHash %= arraySize;

                        }

                        // Couldn't locate the key

                        return (Integer) null;

                    }

                    public void hashFunction2(int[] stringsForArray, int[] theArray) {

                        for (int n = 0; n < stringsForArray.length; n++) {

                            int newElementVal = stringsForArray[n];

                            // Create an index to store the value in by taking
                            // the modulus

                            int arrayIndex = newElementVal % arraySize;

                            /*
                             * 
                             * System.out.println("Modulus Index= " + arrayIndex + " for value "
                             * + newElementVal);
                             */

                            // Cycle through the array until we find an empty space

                            while (theArray[arrayIndex] != -1) {

                                ++arrayIndex;

                                // System.out.println("Collision Try " + arrayIndex +
                                // " Instead");

                                // If we get to the end of the array go back to index 0

                                arrayIndex %= arraySize;

                            }

                            theArray[arrayIndex] = newElementVal;

                        }

                    }

                    // Returns the value stored in the Hash Table

                    public int findKey(int key) {

                        // Find the keys original hash key
                        int arrayIndexHash = key % arraySize;

                        while (theArray[arrayIndexHash] != -1) {

                            if (theArray[arrayIndexHash] == key) {

                                // Found the key so return it
                                System.out.println(key + " was found in index "
                                        + arrayIndexHash);

                                return theArray[arrayIndexHash];

                            }

                            // Look in the next index

                            ++arrayIndexHash;

                            // If we get to the end of the array go back to index 0

                            arrayIndexHash %= arraySize;

                        }

                        // Couldn't locate the key

                        return (Integer) null;

                    }

                    HashFunction2(int size) {

                        arraySize = size;

                        theArray = new int[size];

                        // Fill Array with -1 for each empty space

                        fillArrayWithNeg1();

                    }

                    public void fillArrayWithNeg1() {

                        Arrays.fill(theArray, -1);

                    }

                    public void displayTheStack() {

                        int increment = 0;

                        int numberOfRows = (arraySize / 10) + 1;

                        for (int m = 0; m < numberOfRows; m++) {

                            increment += 10;

                            for (int n = 0; n < 71; n++)
                                System.out.print("-");

                            System.out.println();

                            for (int n = increment - 10; n < increment; n++) {

                                System.out.format("| %3s " + " ", n);

                            }

                            System.out.println("|");

                            for (int n = 0; n < 71; n++)
                                System.out.print("-");

                            System.out.println();

                            for (int n = increment - 10; n < increment; n++) {

                                if (n >= arraySize)
                                    System.out.print("|      ");

                                else if (theArray[n] == -1)
                                    System.out.print("|      ");

                                else

                                                    System.out.printf("| %3s " + " ", theArray[n]);

                            }

                            System.out.println("|");

                            for (int n = 0; n < 71; n++)
                                System.out.print("-");

                            System.out.println();

                        }

                    }

                }

You are trying to convert Integers to ints, and you can't use generics to refer to primitive types.

commented: Exactly, so you must get the Integer[] array and create your int[] array using a loop. +0

worse, he's trying to convert an array to an array using the toArray STATIC method of an instance of List.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.