Win a copy of The Journey To Enterprise Agility this week in the Agile and Other Processes forum! And see the welcome thread for 20% off.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

ArrayList  RSS feed

 
Ranch Hand
Posts: 127
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
consider the following code:
import java.util.*;
class ArrayDemonstration
{
public static void main(String args[])
{
ArrayList list = new ArrayList(2);//line 1
list.add("mango");
list.add("apple");
list.add("mango");
list.add("banana");
Iterator i = list.iterator();
while(i.hasNext())//line 2
{
System.out.print(i.next());//line 3
}

}

}

On the above program i have some queries:
1.In the line marked with line1 the 'ArrayList ' has to accept only 2 elements but its accepting more than 2 elements .I would like to know whether its advisable to place the total no of elements in the 'ArrayList'
2.I would like to know the functionality of the lines marked with line2,line3

tx in advance,
carl..
 
Ranch Hand
Posts: 298
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello carl,
Go through the java api
http://java.sun.com/j2se/1.4.2/docs/api/index.html,

it will give u a better explanation about that,
basically the constructor for the array list which u have used here,
specifies the capacity of the arraylist and not the size, thats not fixed and it increases whenever the number of elements goes beyond the capacity.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!