Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Araylist of objects

 
ichabod
Greenhorn
Posts: 2
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am implementing an ArrayList of objects which are of type StudentInfo for this course registration system I am making. The class StudentInfo contains many variables. I want to do a few things to the ArrayList. The first is search the ArrayList's Objects for a particular field like SocialSecurityNumber. Secondly, I want to be able to access the variables within an object as well as send a copy of the object over a socket connection. I have seen implementations of casting the list into an array which has type Object, but I can not access any of the methods in StudentInfo objects through that. I am really confused, if anyone could help I would appreciate it alot.
 
Bosun Bello
Ranch Hand
Posts: 1510
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to cast the arraylist element you retrieve to it's appropriate type, in this case, studentInfo, then use that reference to access the SSN vsriable, or access the method that will get you the SSN variable.


------------------
Bosun
SCJP for the Java� 2 Platform
 
Marilyn de Queiroz
Sheriff
Posts: 9059
12
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ichabod,

Please do not cross-post. Many people read more than one forum, as you obviously did. I am closing this thread. please refer to http://www.javaranch.com/ubb/Forum1/HTML/002278.html for any further response/questions regarding this subject.

Also, please read http://www.javaranch.com/name.jsp and re-register. We would like you to continue to post here at JavaRanch.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic