aspose file tools*
The moose likes Java in General and the fly likes How to use ArrayList in jdk1.5 Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to use ArrayList in jdk1.5" Watch "How to use ArrayList in jdk1.5" New topic
Author

How to use ArrayList in jdk1.5

Pal Amutha
Greenhorn

Joined: Jan 28, 2008
Posts: 13
import java.util.*;

public class myarraylist {

public static void main(String args[])
{
ArrayList ob1=new ArrayList();
//ArrayList<Alphabet> v=new ArrayList<Alphabet>();
v.add("A");
v.add("B");
System.out.println(v);

}
}

In the above code , it gives warning message.
I refer through net. They used generic. see the comment line.
they mentioned like this way.

the general syntax is :
ArrayList<E> object=new ArrayList<E>();
here , what is E denote. Please explain it
Kaydell Leavitt
Ranch Hand

Joined: Nov 18, 2006
Posts: 689

Welcome Pal Amutha,

Where is the class: Alphabet defined?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18853
    
  40

Even if the Alphabet class is defined somewhere, it is moot. The example uses String objects, not Alphabet objects.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Yes, that is true. As Henry said, the actual type being provided is of type String. So no matter what class you gave, it will complain because of a type mismatch.


Everything has got its own deadline including one's EGO!
[CodeBarn] [Java Concepts-easily] [Corey's articles] [SCJP-SUN] [Servlet Examples] [Java Beginners FAQ] [Sun-Java Tutorials] [Java Coding Guidelines]
Raghavan Muthu
Ranch Hand

Joined: Apr 20, 2006
Posts: 3344

Originally posted by Pal Amutha:
here , what is E denote.


E denotes an Element, as a general shortcut they represent it in a single letter in caps. K for key, V for value etc.,
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How to use ArrayList in jdk1.5