Stephan van Hulst wrote:
Don't use arrays in method signatures or return types. Use collections.
Stephan van Hulst wrote:Arrays are not good for APIs. They're basic building blocks of more advanced data structures. Whether a method is private or not doesn't matter. You're still a consumer of your own private methods, and collections are much more versatile and lead to code that's easier to read. Performance will rarely play a part, because collections that use an array as their backing store (ArrayList, ArrayDeque, ArrayBlockingQueue) shouldn't perform that much poorer.
There might be some caveats, but those will be known by software architects who have a very specific and well thought out reason to use an array instead of a collection, and only after profiling. If you're not sure you need one, then you don't need one.
I suggest you start by writing an explanation of each method call and what it returns; seeing the structure of the code will probably help you enhance it.
Atul More wrote:. . . The code from line 82 on wards till the end to read the list of words and get the count of each word. . . .
Stephan van Hulst wrote:It would be silly for a utility class for array operations, not to work on arrays.
String is an extremely low level data structure. It's not a good example of a high level application API.
Scott Shipp wrote:It sounds like the advice in question is actually centered on "public," "high-level" API's?
Personally, I feel that the space is too complex and there are too many nuances to issue any blanket generalities about using arrays or objects in method signatures. It takes a careful software craftsman to consider the context and make a (hopefully) wise decision. In the given example from the OP, I personally don't object to his use of an array there.
A lot of experienced developers actually say don't use collections, use specific / custom objects.
All of our APIs became screwed up, specifically because we used Java collections in them. Actually, now that I think about it, had we used arrays, we wouldn't have had the same problem.