Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-17-2007, 06:56 PM
Member
 
Join Date: Jul 2007
Posts: 26
romina is on a distinguished road
Use ArrayList Constructor...
hi! I have been looking at the source code for the ArrayList class, and I found a constructor that allows you to make an ArrayList of a given length,
Code:
ArrayList test = new ArrayList(int length);
(source code for ArrayList class) Docjar: java/util/ArrayList.java

But whenever I try to use this constructor, a normal ArrayList is made, not the one with a length of 42 that I want.

So my question is: Does this constructor actually work?

I'd gladly use an array, but using an ArrayList is part of my assignment.
Thanks
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 08-07-2007, 07:37 AM
Member
 
Join Date: Jul 2007
Posts: 40
barney is on a distinguished road
The code you provide a link to doesn't seem to be the code for ArrayList that is inherent to Java. The API for ArrayList specifies the default capacity is 10, where as the code you link to sets the default to 16. Are you using the code you link to or the implementation Java provides for you? (It may not make any difference to this problem however)

Are you using the ArrayList.size() method to determine if the length is 42? If so, you should find that the size method reports only how many items are in the current arraylist, not how many it can hold.

Thus, the following should always print 0:
Code:
ArrayList al = new ArrayList(42); System.out.println(al.size());
ArrayList seems to act a lot like a Vector, which means it's capacity can grow, so my feeling is the initial capacity should be of minimal importance.
Greetings.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Project Trouble: Searching one ArrayList with another ArrayList BC2210 New To Java 2 04-21-2008 01:43 PM
Constructor with enum bugger New To Java 2 01-04-2008 01:21 PM
Calling constructor of parent class from a constructor Java Tip Java Tips 0 12-19-2007 11:10 AM
Calling constructor of same class from a constructor Java Tip Java Tips 0 12-19-2007 11:01 AM
Constructor Help bluegreen7hi New To Java 2 11-15-2007 07:44 AM


All times are GMT +3. The time now is 08:00 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org