• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

ArrayList class

 
Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
which of the following statements are true of the ArrayList class?

1 It can store primitive or references as elements.
2 It implements the List interface.
3 It has a get(int index) method which returns the element at the specified
position in the list.
4 The elements are ordered but not sorted.


pls. let me know the explanation for the correct ans too...

thanks in advance
 
Ranch Hand
Posts: 1296
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The best that you can hope to get when you ask an obvious homework question such as this, is a very helpful link to the ArrayList API. Look through this for about 15 minutes, you should be able to figure it out.
[ February 17, 2006: Message edited by: Garrett Rowe ]
 
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
#1 is patially true
ArrayList can store elements that are Objects. So any reference to a type Object can be directly stored. A primitive like int can be still be store provided its converted to an object. Ex. Integer. ArrayList can also store a null.

#2 True.
Much cannot be explained about this. The definition of ArrayList is like:

public class ArrayList extends AbstractList implements List, RandomAccess, Cloneable, Serializable

#3 True
Refer to the API...http://java.sun.com/j2se/1.4.2/docs/api/

#4 Definetely elements are not sorted in an ArrayList.
Only in TreeSet and TreeMap elements are stored in the ascending order. Both TreeSet and TreeMap implement the SortedSet and the SortedMap interfaces. ArrayList implements only the List interface hence the elements are not automatically stored in the sorted order.

Hope this helps!!

- Mel
 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ArrayList is nothing but implementation of List collection with some specifici properties such as

- elements can take primitive or Objects
- elements are natural ordered but not sorted
- If Arraylist implements Comparable interface then sorting can be invoked on ArrayList
- Arraylist consists of API's such as get,containts,add() etc

Hope this quick capsule helps
 
I love a good mentalist. And so does this tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic