The Artima Developer Community
Sponsored Link

Design Forum
String Util

1 reply on 1 page. Most recent reply: May 12, 2003 3:12 AM by Amrainder

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

String Util Posted: May 11, 2003 8:38 PM
Reply to this message Reply
Advertisement
Hi Guys,

I saw a recent post on this forum about sorting a String Array in this particular order. Basically whatever starts with A should come before B and so on. However the problem was that small "a" should be also capital "B". Which makes the sequence Aa Bb Cc Dd. The problem is I don't think normal ASCII can be used for this purpose of ordering.

Immediately after seeing the problem I thought I could extend String class and then over ride compareTo method which is in the Comparable interface in order to perform this particular comparison. Also thought of defining a static two dimensional Array with the A = 1, a = 2, B = 3 and b = 4. So based on this array I can write to compareTo method and then call array.sort() method to achieve the required output.

However when I sat to write the code I realized that String class is final and cannot be extended. I need some design advice as to how I can design the class? I can manage the coding.


Senthoor


Amrainder

Posts: 1
Nickname: amrainder
Registered: Apr, 2003

Re: String Util Posted: May 12, 2003 3:12 AM
Reply to this message Reply
One solution can be providing an implementation for Interface java.util.Comparator and using it for sorting your String Array, and then you can use
Arrays.sort(Object[] toBeSorted, Comparator stringComparator);

Flat View: This topic has 1 reply on 1 page
Topic: Help -- What do I start with in designing a J2EE project Previous Topic   Next Topic Topic: Guy Steele on growing Java

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use