Results 1 to 6 of 6
  1. #1
    Lamberg is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Question Sorting letters but keeping location number

    Hi all,

    I'm currently working on a book where I have alphabetized the whole book. For that I been using a Java script that looks like this:

    Java Code:
    package lettersort2;
    
    public class Main {
        public static void main(String[] args) {
    String unsorted = "cba";
    char[] content = unsorted.toCharArray();
    java.util.Arrays.sort(content);
    String sorted = new String(content);
    System.out.print(sorted);
    
        
        }
    
    }
    Where cba is this example is the text to sort.

    The thing is that I would like to keep the original coordinate of the letter intact.

    The output now is: abc

    but what I would like is something more in the direction of:

    a,3 b,2 c,1

    But my Java knowledge is very limited so I have no clue how to approach it.

    Anyone that would be so kind to push me in the right direction?
    Last edited by Lamberg; 04-27-2010 at 02:45 PM.

  2. #2
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    806
    Rep Power
    6

    Default

    what output you are expecting?...If we give cba ,it is giving abc.what else you want?
    Last edited by RamyaSivakanth; 04-27-2010 at 03:35 PM.
    Ramya:cool:

  3. #3
    Lamberg is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    With the final sorting (about 30.000 glyphs) I hope to get a long line of sorted letters like:

    A,5 A,200, A,516 and so on...

    Where A is the letter from the original string and the number correspond to the position it had in the original string.

  4. #4
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    806
    Rep Power
    6

    Default

    In java,u have indexOf() method in String class to track the position of letters.Use it.
    In the meanwhile i will find some satest way of doing this with some algorithm and let you know.
    Ramya:cool:

  5. #5
    iluxa is offline Senior Member
    Join Date
    Mar 2010
    Posts
    266
    Rep Power
    5

    Default

    In java,u have indexOf() method in String class to track the position of letters.Use it.
    Won't work :( for string "aabbcc" will return
    a,0 a,0 b,2 b,2 c,4 c,4

    do this:

    - create a new class called MyLetter with two fields: character and position
    - iterate through all characters in your string, and create a corresponding MyLetter object. Keep these objects in ArrayList myLetterList.
    - make sure MyLetter implements Comparable, and returns the correct value for character comparisons
    - call Lists.sort(myLetterList);
    - iterate through myLetterList and print things out.

  6. #6
    Lamberg is offline Member
    Join Date
    Apr 2010
    Posts
    3
    Rep Power
    0

    Default

    You can consider this issue solved.

    I didn't succeed to make an java that worked as supposed to. I also had the problem of that Java couldn't handle my huge amount of information: around 170 000 glyphs (where most where multibyte letters).

    I found the solution by using Excel instead but I thank for all help.

Similar Threads

  1. need to copy file from one location to another location
    By naveen.dpt2007 in forum New To Java
    Replies: 4
    Last Post: 02-28-2010, 03:53 PM
  2. Problem with keeping values into an arrayList
    By Daniel Silvester in forum New To Java
    Replies: 0
    Last Post: 12-02-2009, 01:14 AM
  3. location provider returns no location
    By sandeeprao.techno in forum CLDC and MIDP
    Replies: 0
    Last Post: 09-24-2009, 09:54 AM
  4. Replies: 1
    Last Post: 08-07-2009, 12:14 PM
  5. Java Keeping Text in One Place
    By xpngamer in forum New To Java
    Replies: 1
    Last Post: 04-09-2009, 06:27 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •