Solved

Simple walk through of an array list is giving me an out off bounds exception .

Posted on 2004-10-12
3
439 Views
Last Modified: 2010-03-31
I have created an arrarylist which holds the height of 10,000 binarysearchtrees I'm simply trying to print the height of every tree out of the arraylist. However at index[50000] it is giving me the error. But i print the size of the arraylist before and it is 10000 i just can't figure this out.Any ideas why this is happening would be great

====================code=========================

import java.util.Random;
import java.util.ArrayList;
import java.util.Collections;

public class RandomGenerator
{

      public static void main(String [] args)
      {
        ArrayList binarylist = new ArrayList();
        ArrayList Avllist = new ArrayList();

          AvlTree a;
          BinarySearchTree b ;
          Random random = new Random();
        int numtrees =   10000;              //Integer.parseInt(args[0]);
        int sizetrees =   100;            //Integer.parseInt(args[1]);

        //create binary trees
          for (int i=0; i < numtrees ;i++)
          {
                  b = new BinarySearchTree();
            a = new AvlTree();

                //create # int's inside tree
                  for(int j=0; j < sizetrees; j++)
                  {
                    b.insert(random.nextInt() );
                    a.insert(random.nextInt() );

                }


          binarylist.add(new Integer(b.height()) );
          Avllist.add(new Integer(a.getHeight(a.getRoot() ) ) );


            }



     Collections.sort(binarylist);

     for(int i=0; i < numtrees ; i++)
     {
             System.out.println( binarylist.get(i) );

             binarylist.remove(i);
       }



System.out.println(binarylist.size() + " " +  binarylist.get(4999) );






}



0
Comment
Question by:tyweed420
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 50 total points
ID: 12293472
>>binarylist.remove(i);

You seem to
0
 

Author Comment

by:tyweed420
ID: 12294048
yeah i understand you thanks! dummy me:)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 12296118
:-)

I'm glad you did - my answer seems to be strangely truncated ;-)
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
JavaScript/Java - Changing an image background color 4 67
Java JRE greater than 1.6 5 63
split string containing \r\n in Java 46 44
login form jsp example 2 26
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
This video teaches viewers about errors in exception handling.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question