• 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

Array or Arrays?

 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Neither.

Those are both utility classes that are used to manipulate arrays. Neither is an array.
 
Ranch Hand
Posts: 250
1
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic