aspose file tools*
The moose likes Beginning Java and the fly likes Array or Arrays? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Array or Arrays?" Watch "Array or Arrays?" New topic
Author

Array or Arrays?

Shelby Simpson
Greenhorn

Joined: Feb 17, 2013
Posts: 26
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

Joined: Jan 10, 2002
Posts: 61226
    
  66

Neither.

Those are both utility classes that are used to manipulate arrays. Neither is an array.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Joel Christophel
Ranch Hand

Joined: Apr 20, 2011
Posts: 237
    
    1

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

Joined: Feb 17, 2013
Posts: 26
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

Joined: Oct 13, 2005
Posts: 38881
    
  23
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array or Arrays?