• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Arrays - basic question

 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when we create any array object .
int[] i = new int[3];
the hierarchi is :


is this correct .
thanks .
[ January 31, 2005: Message edited by: rathi ji ]
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi

i think int[]`s direct super class is lang.Object

this code

int[] s=new int[10];
System.out.println(s.getClass().getSuperclass().toString());

gives java.lang.Object as o/p
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hierachy depends if your array is a primitive data type array or a reference type array.

Primitive data types arrays are direct descendants of Object class, but not of Object[].

However reference type arrays are direct descendants of Object[].

So hierachy would be like this for primitive data types


Object
^
byte[] short[] char[] int[] long[] float[] double[] boolean[]

But for reference types:

Object
^
Object[]
^
Integer[] MyClass[] Float[] String[]

Hope it helps!
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Edwin , but what about Arrays class . when it is useful .
thanks a lot .
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can any body tell me , what is the use of Arrays class .

thanks .
 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
http://java.sun.com/j2se/1.4.2/docs/api/index.html

"This class contains various methods for manipulating arrays (such as sorting and searching)."
 
Ranch Hand
Posts: 4982
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

what is the use of Arrays class .



If you are refering to java.util.Arrays, its main usage is to provide utilities (static methods) to manipulate arrays. All of its methods are static (just like java.lang.Math).

Nick
 
ankur rathi
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Nick ,
I got the point . Actually I was thinking that every array is implicitly sub class of Arrays class . But this is not the case , primitives array extends from Object class ( as every other class extends ) & reference variable array extends from Object[] class & that extends Object class . And Arrays class provides static methods for manuprlatings this arrays .

Thanks once again to all .
 
Humans and their filthy friendship brings nothing but trouble. My only solace is this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic