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 Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Simple questions on arrays

 
David Duran
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is the array a primitive datatype or is it an Object?
In terms of overhead, is an array much less than a List object?
Does an array have "member methods" or member fields other than ".length"?
Thanks
 
Sam Zou
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Answer 1 : the array is a primitive data type
Answer 2 : It depends what do you want to do. If you have a lot of insertion to do the List object may be a good idea, the insertion is simple. On the other hand, insertion in an array is a little bit more complicated, you have to manage yourself the insertion.

Answer 3: an array have more than the length member. It has the clone() method. And it inherit all the member and method of the Object class except the clone method.
I hope that the answer is clear enough. If you want more details information take a look at the java Specification.
Java Specification
YLT
 
David Duran
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yves, thanks for the response and the link to the specification.
The array itself will already be filled, all I need to do are gets out of it so for my purpose the array is the better way to go over the List.
 
Dave Landers
Ranch Hand
Posts: 401
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
an array is an Object.
Prove it to yourself:
 
Bert Bates
author
Sheriff
Posts: 8898
5
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
David - Listen to Dave - an array is an object. Also, if when you are getting things back out of the array, if you're making a copy, then the array is fine. However - if you want to get something out and remove it from the array at the same time, ArrayList is the way to go.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic