Return-Path: Delivered-To: apmail-jakarta-commons-user-archive@www.apache.org Received: (qmail 98363 invoked from network); 30 Apr 2004 16:01:45 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 30 Apr 2004 16:01:45 -0000 Received: (qmail 143 invoked by uid 500); 30 Apr 2004 16:01:32 -0000 Delivered-To: apmail-jakarta-commons-user-archive@jakarta.apache.org Received: (qmail 127 invoked by uid 500); 30 Apr 2004 16:01:32 -0000 Mailing-List: contact commons-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Users List" Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list commons-user@jakarta.apache.org Received: (qmail 111 invoked from network); 30 Apr 2004 16:01:32 -0000 Received: from unknown (HELO devolver.fgm.dev) (207.158.50.34) by daedalus.apache.org with SMTP; 30 Apr 2004 16:01:32 -0000 Received: from apache.org (localhost.localdomain [127.0.0.1]) by devolver.fgm.dev (8.12.8/8.12.8) with ESMTP id i3UG1YbH006271 for ; Fri, 30 Apr 2004 09:01:35 -0700 Message-ID: <4092785E.9070907@apache.org> Date: Fri, 30 Apr 2004 09:01:34 -0700 From: "matthew.hawthorne" User-Agent: Mozilla Thunderbird 0.5 (X11/20040208) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: Sorting string array numerically References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N S�ren Blidorf wrote: > I have a problem regarding sorting numerically. > > I have the following pics: > > pic_1, pic_2, pic_3, pic_4, pic_5, pic_6, pic_7, pic_8, > pic_9, pic_10, pic_11, pic_12 > > But the sort makes a sort after first number then second > number: > > pic_1, pic_10, pic_11, pic_12, pic_2, pic_3, pic_4, pic_5, > pic_6, pic_7, pic_8, pic_9 > > How can I make sure that the sort is numeric? > > pic_1, pic_2, pic_3, pic_4, pic_5, pic_6, pic_7, pic_8, > pic_9, pic_10, pic_11, pic_12 I'm not sure if this is the right list for this type of message... But, you could write a custom Comparator, which parses the number from the string. Then you could use java.util.Arrays.asList() to convert your array to a List, use java.util.Collections.sort(List, Comparator) to get the results. I think this will work -- but it will probably be slower than just manually looping through the array and using a StringTokenizer to compare the strings yourself. --------------------------------------------------------------------- To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-user-help@jakarta.apache.org