File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Array or Arrays?

 
Shelby Simpson
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to use an Array and inovke its method calls but I keep getting "cant find symbol" errors. In looking at the java API I can see that there is an Array class and an Arrays class. When I create an array like this - private int[] someArray = new int[24]; what class of array am I calling?

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64178
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Neither.

Those are both utility classes that are used to manipulate arrays. Neither is an array.
 
Joel Christophel
Ranch Hand
Posts: 249
1
Chrome Eclipse IDE
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Shelby Simpson wrote:When I create an array like this - private int[] someArray = new int[24]; what class of array am I calling?

To find out the class of an object, use the getClass() method. You will find that you are creating neither an "Array" or "Arrays" object.



This prints out "class [I". Similarly, [B is the class of the byte array, [C is the class of the char array, etc.

Shelby Simpson wrote:In looking at the java API I can see that there is an Array class and an Arrays class.

Oracle's website explains that these classes "contain various methods for manipulating arrays." To use the methods of these classes with your array, you must make a static reference to the class and pass in your existing array. For example:

 
Shelby Simpson
Greenhorn
Posts: 26
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok I see, I was looking at that all wrong. I didn't know about the getClass method. Thanks for clearing that up for me.
 
Campbell Ritchie
Sheriff
Pie
Posts: 47231
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joel Christophel wrote: . . . make a static reference to the class and pass in your existing array. . . .
You mean “call the static methods on the class name”, just as you do for any static method. You do not actually make a reference to the class. The code was, of course, correct.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic