This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
I was wondering how do I sort an array of records objects that contain string values. The value that I am trying to sort by is the last name. Also, I need to create a method that will sort the array in ascending or descending order by the last name of the objects created. Any help that can be provided concerning this matter will be greatly appreciated. - J. Ward
A couple of questions: 1. When you say that your array of records contains string values and you want to sort by last name, what do you mean exactly? Is this a possible component in the array: "Dirk Schreckmann" This is what I'd guess you mean. 2. Have you run across the The API Specification yet? Taking a look at the documentation for the class String, some useful methods might be compareTo(String), indexOf(int ch), substring(int), and/or substring(int, int). If you were to use a Collection (and the Collections class) you could abstract yourself a bit from the nitty-gritty details of sorting, but String::compareTo(String) already removes one from this quite a bit. Do you have any ideas on where you'd like to begin?