java.lang.ArrayIndexOutOfBoundsException: 8
<p>am new to programming and im trying Java, i created this array and gives me this error, task is to count all positive and negative no and place it in new array i called pArr and nArr, and after that to count duplicates and write them and how many times they repeat, can someone help me?</p>

<pre><code>public static void main(String[] args) {
        int[] array = {12, 23, -22, 0, 43, 545, -4, -55, 43, 12, 0, -999, -87};
        int brPoz=0, brNeg=0;

        for(int a=0; a&lt;array.length; a++){
            if(array[a]&gt;0)
                brPoz++;
            else if (array[a]&lt;0)
                brNeg++;
        }
        int[] pArr = new int[brPoz];
        int[] nArr = new int[brNeg];     

        for (int i = 0; i &lt; array.length; i++) {
            if (array[i] &gt; 0) {
                pArr[i] = array[i];
            }
        }

        for (int i = 0; i &lt; array.length; i++) {
            if (array[i] &lt; 0) {
                nArr[i] = array[i];
            }
        }


        Arrays.sort(array);
        Arrays.sort(pArr);
        Arrays.sort(nArr);
        System.out.println(java.util.Arrays.toString(array));
        System.out.println(java.util.Arrays.toString(pArr));
        System.out.println(java.util.Arrays.toString(nArr));


          for (int i = 0; i &lt; array.length; i++) {
            for (int j = i + 1; j &lt; array.length; j++) {
                if ((array[j])==array[i]) {
                    System.out.println("Duplikati su: "+array[j]);
                }
            }
        }
</code></pre>