Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to use ArrayList in jdk1.5  RSS feed

 
Pal Amutha
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 690
Eclipse IDE Firefox Browser Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome Pal Amutha,

Where is the class: Alphabet defined?
 
Henry Wong
author
Sheriff
Posts: 22837
119
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Even if the Alphabet class is defined somewhere, it is moot. The example uses String objects, not Alphabet objects.

Henry
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raghavan Muthu
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.,
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!