Doubt in compareTo method while sorting string having special character

I used compareTo method of String to sort below strings
??che
??in
p?ch?
I got the output in the below order :
p?ch?
??che
??in
Why does ??che appear before ??in because from http://www.asciitable.com/ ascii value of *?* is *154*
and that of *?* is *130* so shouldn't ??in appear ??che?
Regards,
Joshua

jaay wrote:
I used compareTo method of String to sort below strings
??che
??in
p?ch?
I got the output in the below order :
p?ch?
??che
??in
Why does ??che appear before ??in because from http://www.asciitable.com/ ascii value of *?* is *154*
and that of *?* is *130* so shouldn't ??in appear ??che?
Regards,
JoshuaAre you sure your strings are using ASCII encoding, and not unicode? If it's the latter, the ASCII table won't matter at all and you'd need to check the values in a unicode table.

Similar Messages

  • How Create New Folder in KM with Name having Special Character

    Hi,
    How to create new Folder in KM with name having special character in it.
    Right now its not allowing me to create folder when i have Colon( as one of the character in name of the folder.
    Is there a way to change this validate?
    Any help is appriciated.
    Thanks

    Hi DK,
    I'm not sure about special chars such as ":" but ifyou need to have your folders displaying special language chars (like german chars), have a look into the below link.
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/30deb229-d570-2910-4aaf-8858e0660f05
    Hope that helps.
    Ray

  • Sorting string by first character

    What is the easiest way to sort strings by the first character?  I can sort by a complete string match, but what I really want to do is just sort by the first letter of character.  Is there a way to do something like a reverse concatenate?  
    Thank you
    Danny
    Danny
    Attachments:
    Sort string.vi ‏11 KB

    This is one of those times where I think Regular Expressions can be of use.
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines
    Attachments:
    Sort string_BD.png ‏26 KB

  • Error while releasing transport request -  Special character "_" in generic

    Hi all,
    we're receiving the error  Special character "_" in generic key  when releasing a best practice transport.
    Note 1304725 describes my error, but the solution cannot be implemented. The reason for this is that we do not have an individual entry for eacht yb_PS,..,
    but we have only one entry where field BWERT has a wildcard '*' as entry.
    Does anyone has  some idea how to solve this ?
    kind regards !

    Hello Bjorn,
    How did you get this solved?
    I'm having nearly the same issue:
    A custom-table with a total key lenght of about 365 characters. As soon as I enter a special character (_) in the key field just before the position 120, the message tk287 rejects the entry. Entering the special character in a key field at about key position
    60, there's no message rejecting the entry.
    Regards

  • Invoice Number Having Special Character

    Hi Team,
    we have a requirement to compare Invoice number from master data to child data.
    We are storing the Master Invoice number into variable to access it in Child Data.
    Our issue is the invoice number is having a special character i.e. '-' because of which equal to function is not working.
    Could any one guide on this issue.
    Following is the code
    ?xdoxslt:set_variable($_XDOCTX, 'v1', ssInvoiceNumber)?>
    <?if:(xdoxslt:get_variable($_XDOCTX,'v1')=ssInvoiceNumber)?> Display data <?end if?>
    Even though the data are not same the if loop get executed and its display unwanted data.
    invoice number as (1-100678,1-100677,1-100679).
    Cheers,
    Andy

    do you want to remove HYPHEN from the numbers before comparing ?
    use
    <?translate(ssInvoiceNumber,'-','')?> to remove the HYPHEN
    <?if:(xdoxslt:get_variable($_XDOCTX,'v1')=translate(ssInvoiceNumber,'-',''))?>

  • Reading a string containing special character from a result set

    My Code....
    PrintStream p = new PrintStream(fout);
    if (connection == null)
    connection = getConnection();
    CallableStatement proc = connection.prepareCall("{call testing_read()}");
    rs = proc.executeQuery();
    while ( rs.next() )
    String page2 = rs.getString(1);
    System.out.println(page2);
    rs.getString(1); is a string value eg. 'Rebekah \n Govender' that is being set in a stored procedure.
    The output of my program is :'Rebekah \n Govender' , i need for it to read the special characters, and produce this output :
    Rebekah
    Govender
    Without using a result set , it works fine.
    eg.
    String page2 = 'Rebekah \n Govender'
    System.out.println(page2);
    Will give an output of :
    Rebekah
    Govender
    I need to read values from the results set, pls help me someone....
    Please help....

    String page2 = rs.getString(1).replace("\\n", "\n"); When you include source code in your posts, please enclose it in CODE tags. There's a button for that above the input textarea.
    ThE-MaRaC wrote:
    Hi,
    you can try something like this:
    import java.io.UnsupportedEncodingException;;
    *  Main class, manages the complete game
    public class Main {
    public static void main(String[] args) {
    String page2 = "Rebekah \n Govender";
    try {
    page2 = new String(page2.getBytes("ISO-8859-1"), "ETF-8");
    } catch (UnsupportedEncodingException e) {}
    System.out.println(page2);
    }Regards,
    Hercog MarioThat is a disgusting hack which you shouldn't be recommending to anyone, and it's totally irrelevant here anyway. Also, as written, it does absolutely nothing because you misspelled "UTF-8" and you swallowed the exception that would have told you so.

  • Sort strings. How to make it case-insensitive?

    I wish to sort some String objects. TreeSet does it automatically, but letters are case-sensitive. Is there some static method that sorts Strings without regard to letter cases, so that "String B" will come between "String b" and "String C"?

    SortedSet mySet = new TreeSet(String.CASE_INSENSITIVE_ORDER);
    mySet.add("monkey");
    mySet.add("Zebra");
    mySet.add("Aardvark");
    for(Iterator i = mySet.iterator(); i.hasNext(); ) {
      System.out.println(i.next());
    }I think you probably could have figured that out by looking at the API.

  • Special character "/" replacing with blank with Direct Input Method posting

    Hi All,
    I am posting FI historical data using Direct Input Method. Payment term contains special character "/"( I/E). SAP standard program replacing Special character "/" with blank (I E) so document posting is failing. Could you please advise.
    Thanks
    Chandra.

    Can You please specify the Transaction code and SAP program name for direct input.

  • While trying to invoke the method java.lang.String.length() of an object loaded from local variable 'payload'

    Hi,
    Our PI is getting data from WebSphere MQ and pushing to SAP. So our sender CC is JMS and receiver is Proxy. Our PI version is 7.31.
    Our connectivity between the MQ is success but getting the following error while trying to read the payload.
    Text: TxManagerFilter received an error:
    [EXCEPTION]
    java.lang.NullPointerException: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'payload'
           at com.sap.aii.adapter.jms.core.channel.filter.ConvertJmsMessageToBinaryFilter.filter(ConvertJmsMessageToBinaryFilter.java:73)
           at com.sap.aii.adapter.jms.core.channel.filter.MessageFilterContextImpl.callNext(MessageFilterContextImpl.java:204)
           at com.sap.aii.adapter.jms.core.channel.filter.InboundDuplicateCheckFilter.filter(InboundDuplicateCheckFilter.java:348)
           at com.sap.aii.adapter.jms.core.channel.filter.MessageFilterContextImpl.callNext(MessageFilterContextImpl.java:204)
    I have searched SDN but couldn't fix it. Please provide your suggestion.
    With Regards
    Amarnath M

    Hi Amarnath,
    Where exactly you are getting this error?
    If you are getting at JMS Sender communication channel, try to stop and start the JMS communication channel and see the status, also use XPI Inspector to get the exact error log.
    for reference follow below blogs:
    Michal's PI tips: ActiveMQ - JMS - topics with SAP PI 7.3
    Michal's PI tips: XPI inspector - help OSS and yourself
    XPI Inspector

  • Approval task SP09: Evaluation of approvalid failed with Exception: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'aValue'

    Hi everyone,
    I just installed SP09 and i was testing the solution. And I found a problem with the approvals tasks.
    I configured a simple ROLE approval task for validate add event. And when the runtime executes the task, the dispatcher log shows a error:
    ERROR: Evaluation of approvalid failed with Exception: while trying to invoke the method java.lang.String.length() of an object loaded from local variable 'aValue'
    And the notifications configured on approval task does not start either.
    The approval goes to the ToDO tab of the approver, but when approved, also the ROLE stays in "Pending" State.
    I downgraded the Runtime components to SP08 to test, and the approvals tasks works correctly.
    Has anyone passed trough this situation in SP09?
    I think there is an issue with the runtime components delivered with this initial package of SP09.
    Suggestions?

    Hi Kelvin,2016081
    The issue is caused by a program error in the Dispatcher component. A fix will be provided in Identity Management SP9 Patch 2 for the Runtime component. I expect the patch will be delivered within a week or two.
    For more info about the issue and the patch please refer to SAPNote 2016081.
    @Michael Penn - I might be able to assist if you provide the ticket number
    Cheers,
    Kristiyan
    IdM Development

  • Looking to Search and Sort String Twice, though am having issues

    I am inputing from an access file a test library, the files in the access file are out of alphabetical order...thus I search and sort and bring these into LV in alphabetical order.  But I am running into the issue of trying to further search and sort the second column of info via the model number:
    example:
    Model ............. Model #
    Zetor               55
    Challenger        55
    Ford                55
    Zetor               66
    Challenger        66
    Ford                 66
    Zetor               45
    Challenger        45
    Ford                45
    Zetor               96
    Challenger        96
    Ford                 96
    Need to Return the Files as per below:
    Zetor               45
    Challenger        45
    Ford                45
    Zetor               55
    Challenger        55
    Ford                55
    Zetor               66
    Challenger        66
    Ford                 66
    Zetor               96
    Challenger        96
    Ford                 96
    Attachments:
    search & sort string.JPG ‏65 KB

    actually in my original post I had a brain-lapse on what the final sort needed to be....
    I was looking for this:
    Challenger        45
    Challenger        55
    Challenger        66
    Challenger        96 Ford                 45
    Ford                 55
    Ford                 66
    Ford                 96
    Zetor                45
    Zetor                55
    Zetor                66
    Zetor                96
     thanks for the quick response.

  • I must be losing my mind, Integer  not having a compareTo method?

    import java.util.Comparator;
    @SuppressWarnings("hiding")
    public class IntComparator<Integer> implements Comparator<Integer>
    @Override
    public int compare(Integer o1, Integer o2)
         o1.compareTo(o2);
    Eclipse is claiming that the Integer class does not have a compareTo(Integer) method.

    >
    @Override
    public int compare(Integer o1, Integer o2)
    Eclipse is claiming that the Integer class does not have a compareTo(Integer) method.It will be complaining that Integer does not have a compare method, the specific method you are trying to override that does not exist.
    However the Integer class does have a compareTo() method that you can override, refer to the API
    Mel

  • Understanding Comparable and the compareTo( ) method

    I have a Contact object which lists a person's information for a "phone book" program.
    I am trying to sort the Contact objects in a Vector by way of their last name fields.
    I am having a hell of a time trying to use this compareTo( ) method.
    I'm really struggling with understanding how to go about making the method work with a comparison. Most of the examples which I find compare "numbers' and not strings which make it more difficult to understand.
    I have implimented the comparable Interface at the start of my class. To sort my Vector, I'm attempting to use the compareTo( ) method to determine which Last name field has the lower value. I keep going back and forth working through the error messages I receive and I'm just stumped trying to figure out how to get this thing to work. Can someone please point out the mistakes without writing too much code? I don't want someone to do the work for me. Here is the code:
    import java.io.*;
    import java.util.*;
    class PhoneBook implements Comparable{
         private static Vector v = new Vector();
         private static Iterator iter = v.iterator();
         private static int num, index;
         private static Contact firstContact, secondContact, temp;  //"static" to be referenced from main
         public static void main(String arg[])throws Exception {
              Contact c;
              String str;
              BufferedReader br = new BufferedReader(
          new InputStreamReader(
               new FileInputStream(
                                           new File("contacts.txt"))));
              while((str = br.readLine()) != null){
               v.add(c= new Contact(br.readLine()));
               num = v.size();
               for(int i=0; i < num; i++){
          firstContact = (Contact)v.elementAt(i);
               if(v.elementAt(++i) == null)
                    break;
               else
                    secondContact = (Contact)v.elementAt(++i);
               index = compareTo(firstContact);
               if(index == 1){
                       temp = (Contact)v.elementAt(i);
                       v.setElementAt(v.elementAt(++i), i);
                       v.setElementAt(temp, ++i);
              public static int compareTo(Object person){
         int x = ((Contact)person).getLName().compareTo(secondContact.getLName());
         return x;
    }yet still I get the following compiler error:
    PhoneBook.java:4: compareTo(java.lang.Object) in PhoneBook cannot implement compareTo(java.lang.Object) in java.lang.Comparable; compareTo(java.lang.Object) and compareTo(java.lang.Object) are static
    class PhoneBook implements Comparable{
    ^
    1 error

    You are pretty close here except for one incorrect basic assumption. Your compiler error is because you are trying to implement compareTo() with a static method. However, this is irrelevant because it is not the PhoneBook class that should implement Comparable, but the Contact class.
    The idea is that other functions can call the compareTo() method on an instance of Contact and pass a reference to a second instance. Based on the result, the relative sort order of the two objects can be determined.
    e.g.Contact c1 = new Contact("Smith", "John");
    Contact c2 = new Contact("Jones", "Alan");
    int x = c1.compareTo(c2);In your example, you can implement compareTo() to use the corresponding method in String. For compatibility, you should also implement equals().
    public class Contact implements Comparable {
       public int compareTo(Object otherContact) {
           Contact otherC = (Contact) otherContact;  // could throw exception
           return getLName().compareTo(otherC.getLName());
       public boolean equals(Object otherContact) {
           Contact otherC = (Contact) otherContact;  // could throw exception
           return getLName().equals(otherC.getLName());
    } // end of class Contact I haven't compiled or tested the above code nor does it deal with exceptions (e.g. otherContact is not an instance of Contact) - I'll leave that to you! You'll also need to change your PhoneBook sort routine to invoke firstContact.compareTo(secondContact)
    FYI - I understand that this is an academic exercise and so you may need to code the sort yourself, but once Contact implements Comparable, you could sort the Vector using standard Java methods. Check out java.util.Collections - there is a method that will perform your sort in one line of code.
    Good Luck.

  • Overriding compareTo method for ints

    I'm having a problem writing the overloaded compareTo method for my class. Ideally, the class will be used in collections, and has to be sorted by an int value. I've found a messy way to do this by converting the int values into strings, then comparing those, but I would like to know if there is a better way to do this.

    You could subtract, unless you are worried about over/underflow.
    Then you can just compare the ints the old-fashioned way:
    import java.util.*;
    public class Test implements Comparable<Test> {
        int x;
        public int compareTo(Test that) {
            return this.x - that.x;
            //return this.x < that.x ? -1 : this.x > that.x ? 1 : 0;
    }

  • Java CompareTo Method

    does anyone know how the string compareTo method actually works? I am trying to use a binary search to find a word in an arraylist with a specific prefix.
    i know that the compareTo method returns a 1 0 or -1 based on what the result of the comparison is but im interested in teh actual way that the comparison takes place.
    Since i will be comparing a prefix to a complete word, i would like to know if this would cause any problems due to the difference in string lengths.
    Do you guys have any other idea on how i can use a very fast searching method to search a sorted arraylist of words to see if any word with a specific prefix exists?

    i did that but i would still have to use compareTo because if the middle element does not have the prefix i am looking for then i would have to know if its on the right half or the left half of the Arraylist by comparing. right?
         public static int bSearch(ArrayList list, String pref)
              int result = -1;
              int low = 0;
              int high = list.size()-1;
              String s="";
              while(low <= high || result==-1)
                   int mid = (low + high)/2;
                   s = (String)list.get(mid);
                   if(s.startsWith(pref)==true)
                        result = mid;
                   else if(pref.compareTo(list.get(mid))<0)
                        high = mid - 1;
                   else
                        low = mid + 1;
              return result;
         }this is what i got so far but i am not sure if using compareTo method the way i am using it will work or not.

Maybe you are looking for

  • Mac OS X 10.4.9 Update won't install on my MacBook Pro

    Everytime I try and install Mac OS X Update (Intel) 10.4.9, Java for Mac 10.4 release 5, Quicktime 7.1.5, and iTunes 7.1.1 (either sperately or at the same time, through System Update) I get this message after a period of time: 'A networking error ha

  • Switch over in an environment with multiple standby

    i currently have one primary and one physical standby, I am due to create standby no2 on a different server and then use the new standby as primary ( migrate current primary to a new system) . I like to know 1. if i can create new standby using backu

  • External editor format

    ive just realized when exporting to cs2 i have only a choice between tiff & psd. is this new? i dont remember having this problem before. i need jpegs for what i do in cs2 and so have to open ,close in tiff,reopen and save as jpeg before i can even s

  • FOLDER: launch URL

    Hi All, When the end-users click on a folder icon (on the portal content navigation menu), I want that a certain url is loaded immediatly in the central body. A portal folder has got a property "launch URL", which I expect refers to a url that will b

  • Inserting a column to the right / left ? How to do it?

    When I had a table on my screen, I had an option to incert coluns to right / left of the column that I had highlighted. I don't have that option anymore ( because I clicked on something, I don't remember what). How can I get it back?