• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array class?

 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does array have a corresponding class Class object?
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
private int[] array;
. . .
array = new int[3];
. . .
System.out.println(array.getClass());

Try it.
 
rakesh sugirtharaj
Ranch Hand
Posts: 151
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I did this

package mypack;

public class Test {


public static void main(String[] args) {
int[] array;

array = new int[3];
System.out.println(new Test().getClass());
System.out.println(array.getClass());
System.out.println("After array class");
}
}


and i got the output as

class mypack.Test
class [I
After array class


I dont understand the meaning of that class [I.... Can anyone explain whats going on?
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The "name" of an array class is an open-bracket for each dimension of the array, followed by a descriptor that stands for the type of the array elements. So [I is an array of int, [[D is a double[][], and [java/lang/String; is a String[] .
 
Roger Chung-Wee
Ranch Hand
Posts: 1683
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this also.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic