Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-12
3
Medium Priority
?
448 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 100 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
In this post we will learn different types of Android Layout and some basics of an Android App.
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 …
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Suggested Courses

609 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