I'm attempting to write a method which returns an alphabetical list of Method objects given some arbitrary list of method objects. I cannot for my life figure out why my method keeps missing Method objects starting with 'A'. After methods starting with 'A', everything seems to work fine! Any feedback is much appreciated.
Here's my method to alphabetize method objects:
I'm running my method using a class with the following method names:
And I consistently see the Method BothNegNums() is first! After this, the list is correctly alphabetized (item 2 is 'absNonNeg', 'boo', etc).
I must be missing something simple since the behavior is correct after the 0th item. Thanks for taking a look.
What methods beginning A? I can't see any in your post. There are methods starting a, however. Method names should always start with lower‑case letters, anyway.
Remember, too, that 'Z' in ASCII comes seven places before 'a'.
You've written way more code than you really need to. There are a number of ways you can do this in a single line of code. Google for java sort with comparator equalsignorecase and read through some of the results.
The best ideas are the crazy ones. If you have a crazy idea and it works, it's really valuable.—Kent Beck
Whether you use verbose code depends on your stage of life, at least in part. Students might be told to implement their own algorithms as an exercise, but later, in production, the same people will use ready‑made algorithms because they have been tested widely and designed to cope with corner cases....and not know what differences there are between the versions.
Warning! Way too comfortable! Do not sit! Try reading this tiny ad instead:
SKIP - a book about connecting industrious people with elderly land owners