cancel
Showing results for 
Search instead for 
Did you mean: 

invalid method

Former Member
0 Kudos

does anyone know, i got an error when i try to use method split and replaceAll,

eg. String a ="123";

if i try a.split or a.replaceAll then it will be error. i think split or replaceAll is standard method for string?

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

This depends on which Java version you have, see e.g.

    /**
     * Splits this string around matches of the given 
     * {@linkplain java.util.regex.Pattern#sum regular expression}.
     *
     * <p> This method works as if by invoking the two-argument {@link
     * #split(String, int) split} method with the given expression and a limit
     * argument of zero.  Trailing empty strings are therefore not included in
     * the resulting array.
     *
     * <p> The string <tt>"boo:and:foo"</tt>, for example, yields the following
     * results with these expressions:
     *
     * <blockquote><table cellpadding=1 cellspacing=0 summary="Split examples showing regex and result">
     * <tr>
     *  <th>Regex</th>
     *  <th>Result</th>
     * </tr>
     * <tr><td align=center>:</td>
     *     <td><tt>{ "boo", "and", "foo" }</tt></td></tr>
     * <tr><td align=center>o</td>
     *     <td><tt>{ "b", "", ":and:f" }</tt></td></tr>
     * </table></blockquote>
     *
     *
     * @param  regex
     *         the delimiting regular expression
     *
     * @return  the array of strings computed by splitting this string
     *          around matches of the given regular expression
     *
     * @throws  PatternSyntaxException
     *          if the regular expression's syntax is invalid
     *
     * @see java.util.regex.Pattern
     *
     * @since 1.4
     * @spec JSR-51
     */
    public String[] split(String regex) {
        return split(regex, 0);
    }

Armin

Former Member
0 Kudos

hi Armin,

my Webdynpro developer is on version 2.0.16 and jdk 1.3.1, do you think this cause by java version? or missing library?

Former Member
0 Kudos

Hi,

The <i>split</i> method of the String class was not introduced before jdk 1.4. Since you have jdk 1.3.1, you do not see this method.

Regards,

Satyajit.

Former Member
0 Kudos

hi satyajit,

do you know where i can find JDK documentation? i want to see all the method in 1.4 and 1.3

Former Member
0 Kudos

Hi,

You can go through the javadocs for jdk 1.3.1 <a href="http://java.sun.com/j2se/1.3/docs/api/java/lang/String.html">here</a> and also the javadocs for jdk 1.4 <a href="http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html">here</a>.

Regards,

Satyajit.

Answers (3)

Answers (3)

former_member187990
Participant
0 Kudos

Hi,

An Example Program to describe the wprking of split and replaceAll

public class test {

public static void main(String args[])

{

String a="123";

String a1[]=a.split("2");

String a2=a.replaceAll("1","5");

for(int i=0;i<a1.length;i++)

System.out.println(a1<i>);

System.out.println(a2);

}

}

Output is

1

3

523

(123 is plitted into 1 and 2)

(123 is replaced as 523)

Former Member
0 Kudos

Hai,

Split, replace all methods are inbuit with string class.

http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html

Can you paste your code here?

Regards,

Naga

former_member187990
Participant
0 Kudos

Hi Oscar,

String has certain in built methods such as

split(),

substring(),

subSequence()

replace()

replaceAll()

replaceFirst()

Split will split the given string in to <b>string arrays</b> based on the condition.

replace all will replace the <b>string</b> with given string.