aspose file tools*
The moose likes Java in General and the fly likes Array Methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Array Methods" Watch "Array Methods" New topic
Author

Array Methods

shri kanth
Greenhorn

Joined: Sep 15, 2011
Posts: 2

Hi All,

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

regards,
Shri

Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38392
    
  23
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.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14114
    
  16

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.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
shri kanth
Greenhorn

Joined: Sep 15, 2011
Posts: 2
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
Sheriff

Joined: Oct 13, 2005
Posts: 38392
    
  23
You're welcome


. . . but be careful about saying Campbell's anything is really good
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Array Methods