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

Posted on 2004-10-12
Medium Priority
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


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() ) ) );



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


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


Question by:tyweed420
  • 2
LVL 86

Accepted Solution

CEHJ earned 100 total points
ID: 12293472

You seem to

Author Comment

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

Expert Comment

ID: 12296118

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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

587 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