Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Beginning Java and the fly likes Java Tutorial about List Interface. Question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Java Tutorial about List Interface. Question" Watch "Java Tutorial about List Interface. Question" New topic
Author

Java Tutorial about List Interface. Question

Nick Widelec
Ranch Hand

Joined: Feb 28, 2013
Posts: 226

Hi all,
Do you know what the "val == null" flow control line mean? It is not related to the iteration of the list, what kind of value is "E val" suppose to be?
Studying for the OCP that's why i need to know all these details.

Thanks in advance.
The following bit of code has been taken from http://docs.oracle.com/javase/tutorial/collections/interfaces/list.html
The line of code I do not get, is the one commented out just to highlight the line within the code.


OCAJP 7, OCPJP 7
Winston Gutkowski
Bartender

Joined: Mar 17, 2011
Posts: 7545
    
  18

Nick Widelec wrote:Do you know what the "val == null" flow control line mean? It is not related to the iteration of the list, what kind of value is "E val" suppose to be?

Well, in the particular case you show, it's trying to find the element to replace. There's nothing in the rules that says a List can't contain null elements, and using equals() to check whether an object equals null doesn't make sense, because, in order to call the method, the object can't be null (and besides, you'll get a NullPointerException).

HIH

Winston

Isn't it funny how there's always time and money enough to do it WRONG?
Articles by Winston can be found here
Mansukhdeep Thind
Ranch Hand

Joined: Jul 27, 2010
Posts: 1157

Welcome to the ranch.

Do you know what the "val == null" flow control line mean? It is not related to the iteration of the list, what kind of value is "E val" suppose to be?


I believe you are new to Java language? Is that correct?


~ Mansukh
Jeff Verdegan
Bartender

Joined: Jan 03, 2004
Posts: 6109
    
    6

Nick Widelec wrote:what kind of value is "E val" suppose to be?


http://docs.oracle.com/javase/tutorial/java/generics/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Java Tutorial about List Interface. Question
 
Similar Threads
How to refresh a StringBuffer object for creating a HashMap object
Taking input with Scanner : need to exit on pressing enter key
Generics and casting
need help with school project
jquery - code review