Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Developer
Posts: 112
Registered: ‎05-20-2011
My Device: 9800
My Carrier: Developer

how to short this string array String str[]={"jan2011","feb2011","jan2010,"mar2012"};

Please help me to short following String arry

   String str[]={"jan2011","feb2011","jan2010,"mar2012"};        

How do I sort this  like: jan2010,jan2011,feb2011,mar2012

thanks for advance(not to use string functions more )

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to short this string array String str[]={"jan2011","feb2011","jan2010,"mar2012"};

http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/util/Arrays.html#sort(java.lan... net.rim.device.api.util.Comparator)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 112
Registered: ‎05-20-2011
My Device: 9800
My Carrier: Developer

Re: how to short this string array String str[]={"jan2011","feb2011","jan2010,"mar2012"};

thank u

      please provide me some code.here i can't understand Comparator

 

 here Object[]=str;

      Comarator=?

             public static void sort(Object[] a, Comparator c)



Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to short this string array String str[]={"jan2011","feb2011","jan2010,"mar2012"};

you have to implement the comparator interface.
check the javadoc about the details:
http://www.blackberry.com/developers/docs/6.0.0api/net/rim/device/api/util/Comparator.html#compare(j... java.lang.Object)
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: how to short this string array String str[]={"jan2011","feb2011","jan2010,"mar2012"};

[ Edited ]

You can't sort these Strings correctly into date order, without interpreting the String values in some way.  So you are going to have to write something that knows that jan2010 should be sorted like 012010, and feb2011 should be sorted like 022011.  The easiest approach I suspect is to use SimpleSortingVector and create your own Comparator that converts the String to a value that can be compared. 

 

Edit: Apologies, when I opened this, SImon had not replied, but clearly he did so between my opening and my posting, in fact a lot happened.  So ignore my post.  Content left in since following posts reference it. 

Developer
Posts: 16,992
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: how to short this string array String str[]={"jan2011","feb2011","jan2010,"mar2012"};

no need for a simplesortingvector, arrays can be sorted directly.
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 638
Registered: ‎07-02-2009
My Device: Not Specified

Re: how to short this string array String str[]={"jan2011","feb2011","jan2010,"mar2012"};

[ Edited ]

Look at the KeywordFilterDemo that is zipped with JDE samples for implementation/usage of Comparator. However, I don't think Comparator won't be handy to achieve what you want.

Thanks and Regards,
PraveenGoparaju.