• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

what is this?

 
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what is the use of this?? Is this a dynamic array declaration?? how can we use it??

ArrayList list= new ArrayList();
 
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
reading the api docs will tell you 'what'
http://java.sun.com/j2se/1.5.0/docs/api/java/util/ArrayList.html

searching the forums/google for
"new ArrayList"
will give you plenty of examples on 'how'
 
catherine matthews
Ranch Hand
Posts: 78
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks micheal...

now let say i have initialized ......
ArrayList abc = new ArrayList();

then i need to add string elements into the array
so i just put like
abc.add()
then if i want to get the elements from other methods how do i call them?
abc???

please help
 
Michael Dunn
Ranch Hand
Posts: 4632
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
from the api docs these are the methods you need
abc.add(..)
abc.get(..)

note:
ArrayList abc = new ArrayList();

it is much better this way
List abc = new ArrayList();

and if using any awt components in your program, you will need it as
java.util.List abc = new ArrayList();

you probably won't understand why, at this stage, but a good habit to get into
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

you probably won't understand why, at this stage, but a good habit to get into


An habit you don't understand is not a good habit
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Catherine, it's probably a good idea for you to learn the basics of Java very well first by for example looking at the Learning the Java Language and Essential Java Classes tutorials.

After that, have a look at the Collections tutorial.
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey,

i have tried to make a simple program on how you can use the array list...but is so late and i though like i shuld give my contribution..

the ArrayList creates an array of list which a programmer can use..to use the arraylist you have to import from the java classes..

you create an array list by: ArrayLIst myList = new ArrayList () ;

then you have to create the objects which will be referencing to the your ArrayList myList.

You add the object by method : myList.add(object_name) ; like in my sample program: myList.add(name);

THE USE OF THE ARRAYLIST is when you want to create many objects to a single array. This is like saying...you have an array of students and you want their NAMES, AGE. Then you can create an array list of students and call the objects name and age which will be referencing to the arraylist

import java.util.ArrayList;

public class ArrayLists
{
public static void main(String[] args)
{
ArrayList myList = new ArrayList ();
String name ;
int listLength ;
System.out.println("Welcome");

listLength = Keyboard.readInt("Enter length of the array : ");

for (int i = 0 ; i < listLength ; i++ )
{
name = Keyboard.readString (" Enter your name : ");
myList.add( name);
}
for (int i = 0 ; i < myList.size() ; i++)
{
System.out.println(myList);
}
}
}

Ooooppppsssssssss!!!

i hope i did not confuse you.....

....i am a new babe here and also in programming...

i think this is a nice link...just try to see how it can help you

http://leepoint.net/notes-java/data/collections_non_generic/20lists/20arraylist.html
 
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Dunn:
from the api docs these are the methods you need
abc.add(..)
abc.get(..)

note:
ArrayList abc = new ArrayList();

it is much better this way
List abc = new ArrayList();

and if using any awt components in your program, you will need it as
java.util.List abc = new ArrayList();

you probably won't understand why, at this stage, but a good habit to get into



That's quite the generalization. I use AWT and Swing on a daily basis and have never needed to fully qualify my java.util.List just because I imported an AWT or Swing class. The only way you would have this problem any time you use any AWT component is if you imported java.awt.*, in which case I would say that habit needs to be ejected.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic