Methode in a String

Hi,
I want search a char in a String.
What is the method to do it please?
thank you

You can use indexOf (converting your char to a string) or use this method:int indexOf (String str, char ch) {
    char[] chars = str.toCharArray ();
    int i = 0;
    int n = chars.length;
    while ((i < n) && ch != chars) {
i ++;
return (i == n) ? -1 : i;
}Kind regards,
  Levi

Similar Messages

  • 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

  • What does the trim() method of the String class do in special cases?

    Looking here ( String (Java Platform SE 7 ) ), I understand that the trim() method of the String class "returns a copy of the string, with leading and trailing whitespace omitted", but I don't understand what the last special case involving Unicode characters is exactly.
    Looking here ( List of Unicode characters - Wikipedia, the free encyclopedia ), I see that U+0020 is a space character, and I also see the characters that follow the space character (such as the exclamation mark character).
    So, I decided to write a small code sample to try and replicate the behaviour that I quoted (from the API documentation of the trim method) in the multi-line comment of this same code sample. Here is the code sample.:
    public class TrimTester {
        public static void main(String[] args) {
             * "Otherwise, let k be the index of the first character in the string whose code
             * is greater than '\u0020', and let m be the index of the last character in the
             * string whose code is greater than '\u0020'. A new String object is created,
             * representing the substring of this string that begins with the character at
             * index k and ends with the character at index m-that is, the result of
             * this.substring(k, m+1)."
            String str = "aa!Hello$bb";
            System.out.println(str.trim());
    However, what is printed is "aa!Hello$bb" (without the quotes) instead of "!Hello$" (without the quotes).
    Any input to help me better understand what is going on would be greatly appreciated!

    That's not what I was thinking; I was thinking about the special case where the are characters in the String whose Unicode codes are greater than \u0020.
    In other words, I was trying to trigger what the following quote talks about.:
    Otherwise, let k be the index of the first character in the string whose code is greater than '\u0020', and let m be the index of the last character in the string whose code is greater than '\u0020'. A new String object is created, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m+1).
    Basically, shouldn't the String returned be the String that is returned by the String class' substring(3,9+1) method (because the '!' and '$' characters have a Unicode code greater than \u0020)?
    It seems to not be the case, but why?

  • Execute method to a string written in another string

    Hi all,
    I need help...!!
    I must call a function/method on a string written in another string like this:
    String s1 = "GR0000";
    String s2 = "substring(0,s1.length()-2)";
    I want execute
    s1.substring(0,s1.length()-2)
    from s1,s2, how can i do it?
    Thank you in advice!!!

    Hi all,
    I need help...!!
    I must call a function/method on a string written in
    another string like this:
    String s1 = "GR0000";
    String s2 = "substring(0,s1.length()-2)";
    I want execute
    s1.substring(0,s1.length()-2)
    from s1,s2, how can i do it?
    Thank you in advice!!!Advance.
    I assume that you want the equivalent of a javascript eval() function ?
    Seek for it not in java! What you want is a script interpreter. What you could do is wrap the string in a string representing a java class, write that string to disk as a java file, compile it, have the ClassLoader suck it up and execute it. Viola. The jsp-way; the hard way, but the only way.
    If I'm wrong about your intentions, then tell me. I can't seem to figure it out totally. But good luck anyway.

  • Is there any native method for converting String value to Hungarian notat..

    Hello. there.
    This might be very simple question. but I'm just curious about this.
    I am wondering if Java API offer the any native method for converting uppercased string value to lowercase which obey the Hungarian notation.
    What I'm going to do is using Reflection for excuting RFC function on SAP. I was found it is very similar to JDBC Programming.
    Please refer to blow codes.
    //mTable
    JCoTable mTable = function.getTableParameterList().getTable(rtnTblNm);
        for (int i = 0; i < mTable.getNumRows(); i++) {
         mTable.setRow(i);
         HashMap tmpData = new HashMap ();
              for (int j=0; j < mTable.getNumColumns(); j++) {
                     // I want to set key String [userNo] instead of  [USER_NO] here.
              tmpData.put(mTable.getMetaData().getName(j).toLowerCase(), mTable.getString(j));
              result.add(tmpData);
    } Basically, The idea was from ibatis framework [com.ibatis.common.beans.classInfo] dropcase();
    Any idea would be very helpful for me. Thank you.
    Edited by: hosung.seo on Aug 30, 2009 10:42 PM
    Edited by: hosung.seo on Aug 30, 2009 10:50 PM

    ejp wrote:
    Hungarian notation is a representation of logical/arithmetic expressions in postfix form. Not what you're talking about.
    So your title is very confusing to the people here who know what it means, which is probably all of them, because people read threads based on their title.From now on, I will pay more attention when I post an question.
    If the titile as " +Is there any native method for converting String value to camelcase?"+ would be easier to what i'm pointing at.
    As I mentioned in above sorce code, converting [USER_NO] to [userNo] isn't relevant Hungarian notation. yes, it was ambiguous. Agree! :)
    But some answer wasn't fit to converting case or recognizing "underscore" delimiter. I was expecting toCamelCase() such as blew. Thanks.
        public static String toCamelCase(String name) {
            String lowerName = name.toLowerCase();
            String[] pieces = lowerName.split("_");
            if (pieces.length == 1) {
                return lowerName;
            StringBuffer result = new StringBuffer(pieces[0]);
            for (int i = 1; i < pieces.length; i++) {
                result.append(Character.toUpperCase(pieces.charAt(0)));
    result.append(pieces[i].substring(1));
    return result.toString();

  • I need a replace method for a string buffer

    I am not a Java programmer but I have been working with programming languages for a number of years.
    What I have is some code that returns a hyperlink into a string buffer and then passes that buffer back to the web page that called it inserting the HTML so the page can be displayed.
    I need to replace certain characters in that variable prior to it being handed back to the web page.
    I was hoping for a code snippet that would like me do this.
    Can someone help?
    Thanks

    I am afraid the syntax is escaling me here.Time to brush up on your Java syntax then.
    Sun's basic Java tutorial
    Sun's New To Java Center. Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
    http://javaalmanac.com . A couple dozen code examples that supplement The Java Developers Almanac.
    jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
    JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
    Bruce Eckel's Thinking in Java (Available online.)
    Joshua Bloch's Effective Java
    Bert Bates and Kathy Sierra's Head First Java.
    James Gosling's The Java Programming Language. Gosling is
    the creator of Java. It doesn't get much more authoritative than this.
    Can you show me an example of how to incorporate it
    on an existing String Buffer?Do you know how to call a method on a String Buffer( Like say append)? Do you know how to do a loop?

  • Calling a method with a string

    Here's the question:
    I want to call a method with the name equal to a string variable.
    For example, if the string variable contains "hellojava" , i'd like the hellojava() method to be called..
    if the string contains "error", the error() method should be called..
    and so on..:)

    Here is an example I had thrown together for this
    purpose of the exact demonstration, Ar'nt you in luck.:-). If there is anything you don't understand,
    I can be reached at [email protected] and will be happy to help....
    import java.lang.reflect.*;
    import java.io.*;
    class Test {
         String name = "Default";
            public Test(String name) {
                    this.name = name;
            public void test() {
                    System.out.println("Hello");
         public void count() {
              for(int i=0; i<10; i++) {
                   System.out.println(i);
           public static void main(String[] args) {
                 try {
                         Test myObject = new Test("test1");
                             Class myClass = myObject.getClass();
                   BufferedReader bRead =
                        new BufferedReader(
                        new InputStreamReader( System.in ));
                   String bufStr = null;
                   while( (bufStr = bRead.readLine()) != "exit") {
                         Method noParams = myClass.getDeclaredMethod(bufStr, new Class[] {});
                              noParams.invoke(myObject, new Object[] {});
                }catch(Exception e) {
                   System.out.println("No Such Method.");
    }Good Luck,
    -- Ian

  • UNIX Problem with method Runtime exec(String[],String[],File)

    Hello !!
    i'm french
    scuse my english
    I got a probleme with method exec(String[],String[],File) of Runtime Class
    i don't have any probleme when my program runs on Windows NT but the same program on UNIX doesnt execute my command..
    When i use exec(String[]) methode i dont have this problem ...but i need the second one methode because i have to execute my command in a different directory than the JAVA program.
    I need that results of this command are placed in this drectory so that i can't use an exex() like that :
    exemple with a perl :
    "perl /toto/titi/hello.pl"
    I want to execute this :
    "perl hello.pl" (and hello.pl is placed in /toto/titi)
    Conclusion :
    the exec(String[],String[],File) solution is ok with NT ...
    but with UNIX ????
    Is there other solution ??
    Should i do a "cd" command before my execution ? how can i do this ??
    Thanks !!!!

    Could you post your source code (only relevant part)
    Raghu

  • Invoking a procedure/method via a string

    I know this is probably a long shot, but I will ask anyway...
    What I would like to do is invoke a procedure/method in a class/package which is not the current one by building a string which makes up the call and the parameters and then running it somehow. PLUS, I would like to receive a return value or object from the call....
    eg.
    String command = "getname(id)";
    retval = dummy.execute(command);
    I have looked at RMI, but it does not seem to go this far...
    suggestions would be much appreciated...

    I know this is probably a long shot, but I will ask
    anyway...
    [snip]
    I have looked at RMI, but it does not seem to go this
    far...
    suggestions would be much appreciated...What you are looking for is not RMI, but Reflection.
    Specifically, you will be performing roughly the steps, as explained by calling the String.indexOf(String) method...// import java.lang.reflect.*;
    // Identify the object being called
    Object methodOwner = "This is a test";
    // Identify the class containing the method definition
    Class methodClass = String.class;
    // Identify the method parameters
    Class[] paramTypes = new Class[] { String.class };
    // Find the method *1
    Method method = methodClass.getMethod("indexOf", paramTypes);
    // Create the argument list
    Object[] params = new Object[] { "test" };
    // Invoke the method *2
    Object result = method.invoke(methodOwner, params);
    System.out.println(result); // Prints the Integer with value 10Note that exceptions may be thrown at marks *1 and *2, of which the InvocationTargetException at *2 will probably of most interest, meaning that an exception ocurred in the method being invoked - the exception that was thrown can be found by the getTargetException() method on the InvocationTargetException.
    Hope this helps,
    -Troy

  • Execute method by the string name

    Well,
    I want execute a method , just knowing the string name of her and your class too:
    public class A
    public static void Kick()
    public class B
    final String methodToBeExecuted="Kick";
    Or on the same class too.
    This is possible?
    (In C I could use functions pointers on an array)
    A solution can use @Anotation ou "Reflection"
    Thanks

    i've never seen anything like that, my advice is to
    look closer at your design because your problem is
    very easy to circumventOk but this is not a desing problem.
    It's just a performatic problem.
    Im coding an emulator and need to handle opcode.
    swicth (opcode)
    case 0x1:
      method1();
    case 0xA:
      methodA();This code (one processor that have 256 instructions) can produce a slow program and change it to a thing like this:
    final String instruction = "method" + opcode;Is very very very fast... and build an emulator we nedd to forget a little about the patterns and good pratices and make performatic things.
    understood?

  • 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.

  • How to code a method that returns string for class object

    I have a class named Address.
    public class Addresss{   
    private String street;   
    private String city;            // instance variables  
    private String zipcode;}I have been asked to write a method that returns a string for Address object. I dont understand how to create address object.Can anyone pls help me understand.
    do I have to write (for creating object)
    Address addressObject  = new Address(); ( coding method that returns a string for address object) ---> I really dont understand this part.

    looks almost right. The problem is that your method name AddressBookEntry does not match the name of your class AddressBook and therefore is not a constructor.
    Furthermore, you probably need to make a distinction between a single entry into the address book which consists of a single name and a single address, (which is just what you have done) and an address book itself which is probably a list of AddressBookEntries
    So for your code I would change the class that you called "AddressBook" to "AddressBookEntry" and have a third class that represents the collection of AddressBookEntries.
    Now to be honest, I don't know why you keep the name split apart from the street address portion of the address. I would be more inclined to keep the name as a field of the address itself, but it's your code, you carve it up the way you like.

  • Any input methods to get strings or integers?

    I'm looking for an imput method to get a string or an integer from the command line. If anyone would help me and give me a command to do this, it would be much appreciated. Also, to include source would be nice too.

    import java.io.*;
    public class TrivialApplication {
         public static void main(String args[]) throws IOException {
              BufferedReader readInput = new BufferedReader(new InputStreamReader(System.in));
              int numbernames;
    String numnames;
              int i, j;
              String temp;
              int sortby;
              int clearbuff;
              System.out.println( "Input the number of names that you'd like." );
    numnames = readInput.readLine();
    numbernames = Integer.parseInt(numnames);
              String names[] = new String [numbernames];
              String ages[] = new String [numbernames];
              for (i = 0; i < numbernames; i++)
                   System.out.println( "What's the name?");
                   names[i] = readInput.readLine();
                   System.out.println( "What's the age?");
    ages[i] = readInput.readLine();
              System.out.println( "Do you want to sort by name or age(1 for name, 2 for age)");
              do
                   sortby = System.in.read() - 48;
              while (sortby != 1 && sortby != 2);
         if (sortby == 1)
              for (i = 0; i < numbernames; i++)
                   for (j = 0; j < numbernames - 1; j++)
                        if (names[j].compareTo(names[j+1]) > 0)
                             temp = names[j];
                             names[j] = names[j+1];
                             names[j+1] = temp;
                             temp = ages[j];
                             ages[j] = ages[j+1];
                             ages[j+1] = temp;
         if (sortby == 2)
              for (i = 0; i < numbernames; i++)
                   for (j = 0; j < numbernames - 1; j++)
                        if (ages[j].compareTo(ages[j+1]) > 0)
                             temp = names[j];
                             names[j] = names[j+1];
                             names[j+1] = temp;
                             temp = ages[j];
                             ages[j] = ages[j+1];
                             ages[j+1] = temp;
         System.out.println( "Here they are again for you" );
         System.out.println( "---------------------------" );
         for (i = 0; i < numbernames; i++)
              System.out.println (i + ".) " + names[i] + "\t" + ages);

  • EJB method returns 2D String array

    Hi,
    one of EJB method returns a 2 dimensional array of String. Is it okay? Is this a good EJB programming practice?
    Thanks
    Sabir

    Its ok. but not consdered as best practice now.
    Check out the DTO pattern(previously called value obects from sun's site.
    --Ashwani                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • Help Needed : Setting JDBC Datasource in Crystal XI using Sybase 12.5??

    All, We are migrating our systems to the Crystal XI from Crystal 9 Reporting Servers. I need some technical assistance on the Java API ( use of the Datasources) . Problem: Currently in Crystal 9 we are using OLEDB datasources to connect to various Sy

  • Drop down Menu not working.

    <!DOCTYPE HTML> <html> <head> <title>Riding Bean Abridged</title> <link href="RidingBean/RBAStyle.css" rel="stylesheet" type="text/css"> </head> <body bgcolor="#000000" text="#FFFFFF" link="#FF0000" vlink="#0000FF" alink="#FF00FF"> <p><img src="../Gr

  • Colons within document stored as XMLtype

    Have uploaded a document in a 10g database, the document has : within the element names. We received the errors ORA-31011:XML parsing failed ORA-19202: Error occurred in XML processing LPX-00601: Invalid token in: '//a:b' Have discovered that the pro

  • How to update batch (LIPS-CHARG) using FM WS_DELIVERY_UPDATE

    Hi guys, I posted a question regarding a function module here: How to update batch (LIPS-CHARG) using FM WS_DELIVERY_UPDATE If you have experience about this FM, kindly visit the link and share your wisdom. Thanks. Regards, Carl

  • Need to sync my new iphone5 calendar to my ipad calendar

    Here is what I hope is enough detail to assist in helping me sync my iphone5 calendar to my ipad calendar. I have an ipad2 which is set up under my general family email address.  I recently purchased my wife an iphone4S and used the same email addres