Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / April 2006

Tip: Looking for answers? Try searching our database.

Put chars from String into alfabetical order

Thread view: 
Michael - 22 Apr 2006 01:12 GMT
Hi, Im stuck.
I want to have a method with:
- a parameter String s
- in the body it breaks the String s apart into chars then the chars
are put into alfabetical order.
- the return would give a String in alfabetical order.

In other words:
private String scramble(String s)
{
// put the chars from the string into alfatbetical order (black box)
return s;
}

Any suggestions?

Regards,

Michael (The Netherlands)
Patricia Shanahan - 22 Apr 2006 01:34 GMT
> Hi, Im stuck.
> I want to have a method with:
[quoted text clipped - 15 lines]
>
> Michael (The Netherlands)

Read the API documentation for each of these:

String method toCharArray. java.util.Arrays, String constructors.

Patricia
Michael - 22 Apr 2006 01:52 GMT
Thanks, these libraries are great :D
My solution:

private String scramble(String s)
{
    int i;
    String result ="";
    char [] chararray;
    chararray = s.toCharArray();
    Arrays.sort(chararray);

    for(i=0; i<s.length(); i++)
    {
    result+=chararray[i];
    }
    return result;
}
Patricia Shanahan - 22 Apr 2006 01:56 GMT
> Thanks, these libraries are great :D
> My solution:
[quoted text clipped - 13 lines]
>     return result;
> }

You can make this better by taking another look at the String constructors.

Patricia
Greg R. Broderick - 23 Apr 2006 14:53 GMT
"Michael" <exquisite@zeelandnet.nl> wrote in news:1145667136.871120.118540
@z34g2000cwc.googlegroups.com:

> Thanks, these libraries are great :D

Depending on what sort of course this program is for, your professor may want
you to implement your own sort rather than using a library implementation.

Cheers
GRB

Signature

---------------------------------------------------------------------
Greg R. Broderick                 [rot13] terto@oynpxubyvb.qlaqaf.bet

A. Top posters.
Q. What is the most annoying thing on Usenet?
---------------------------------------------------------------------

Roedy Green - 22 Apr 2006 04:06 GMT
>private String scramble(String s)
>{
>// put the chars from the string into alfatbetical order (black box)
>return s;
>}

you could look on this as:

1. how do I convert String to char[] ( see
http://mindprod.com/applets/converter.html )

2. how do I sort the char[] (see http://mindprod.com/jgloss/sort.html
)

3. how do I convert the char[] back to a String ( see
http://mindprod.com/applets/converter.html )

Signature

Canadian Mind Products, Roedy Green.
http://mindprod.com Java custom programming, consulting and coaching.



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.