| 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: 32654
|
|
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
Bartender
Joined: Aug 16, 2005
Posts: 12911
|
|
|
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: 32654
|
|
You're welcome
. . . but be careful about saying Campbell's anything is really good
|
 |
 |
|
|
subject: Array Methods
|
|
|