File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes i cant understand this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "i cant understand this code" Watch "i cant understand this code" New topic

i cant understand this code

alex lotel
Ranch Hand

Joined: Feb 01, 2008
Posts: 191

i am new to all this < > consept
i can guess that the new object is called "names"
and that they stack Brian into "names"

can some one explain what <> does??
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63862

Please be sure to take the time to compose descriptive subjects for your posts; read this for more information.

I almost closed this post thinking that it was a duplicate of your other post with this exact same subject.
[ March 15, 2008: Message edited by: Bear Bibeault ]

[Asking smart questions] [About Bear] [Books by Bear]
Nhat Nguyen

Joined: Jan 09, 2008
Posts: 9
you can understand like this:
List<String>: list of string
List<Integer>: list of integer
List<YourBean>: list of YourBean object
Ulf Dittmer

Joined: Mar 22, 2005
Posts: 42965
It helps to compare it to the code without the < ... > stuff (that's called Generics, by the way, and you can find an introduction here).

The only difference is that you need to cast the object the get method returns to a String, because a List contains Object instances (while List<String> is guaranteed to contain String instances - which don't need to be cast).

The other differences is that if you use List<String> and ArrayList<String> the compiler can check that only String objects are added to the list. This would not work:

while this does
alex lotel
Ranch Hand

Joined: Feb 01, 2008
Posts: 191
what is the difference between list and vector??
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46368
Have you read the links I posted for you a couple of days ago?
I agree. Here's the link:
subject: i cant understand this code
It's not a secret anymore!