• 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 Methods

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi All,

Why Arrays methods are static ? Is there any concept behind keeping these and Collections methods as static.

regards,
Shri

 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch

Have a look at the Campbell Ritchie Classification of Methods. The methods in the Arrays class do not take any information from anywhere in an Arrays objecy, nor do they send any information to anything in an Arrays object. So they can be static.

You can try creating an Arrays object to see whether you can get any information into or out of it, and you can't.
So what is the point of an Arrays object? So they have prevented you creating an Arrays object in the first place.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The classes java.util.Arrays and java.util.Collections are classes with utility methods for working with arrays and collections. It would not make much sense if they were not static, that would mean you have to create a dummy instance of those classes to be able to call the methods.
 
shri kanth
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you Campbell.

Yes that make sense that these to be static methods. Avoiding unnecessary object creation. Thanks for the quick replies. And Campbell's classification of methods is really a good guide on deciding a method to be static or non-static.

Shrikanth
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're welcome


. . . but be careful about saying Campbell's anything is really good
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic