Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

public (static) swap() method vs. redundant (non-static) private ones…

807580May 3 2010 — edited May 4 2010
I'm revisiting data structures and algorithms to refresh my knowledge and from time to time I stumble across this problem:

Often, several data structures do need to swap some elements on the underlying array. So I implement the swap() method in ADT1, ADT2 as a private non-static method. The good thing is, being a private method I don't need to check on the parameters, the bad thing is redundancy. But if I put the swap() method in a helper class as a public static method, I need to check the indices every time for validity, making the swap call very unefficient when many swaps are done.

So what should I do? Neglect the performance degragation, or write small but redundant code?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 1 2010
Added on May 3 2010
8 comments
178 views