Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

i cant understand this code

 
alex lotel
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
Marshal
Pie
Posts: 64835
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Nhat Nguyen
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can understand like this:
List<String>: list of string
List<Integer>: list of integer
List<YourBean>: list of YourBean object
...
 
Ulf Dittmer
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between list and vector??
 
Campbell Ritchie
Sheriff
Pie
Posts: 48954
60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the links I posted for you a couple of days ago?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic