Home Java SCJP SCWCD Servlet Submit News Contact Us Site Map


Over 500 magazines for free (including Oracle Magazine)!

Yes all of them are FREE. You can subscribe to ALL of them.
Click here to apply today!

Home > Java > Java Articles

String Manipulation

3. ) Replacing characters in String

The replace method of String can be used to replace all occurrences of the specified character with given character.

String replace(char oldChar, int newchar)


4. ) Getting substrings

String class provides substring method to extract specified portion of the given String. This method has been overloaded.

String substring(int startIndex)
String substring(int startIndex, int endIndex)

Note : A new String object containing the substring is created and returned. The original String won’t be affected.

If the index value is not valid, a StringIndexOutOfBoundsException is thrown.

5. ) Conversions

String class provides set of static overloaded valueOf method to convert primitives and object into strings.

static String valueOf(Object obj)
static String valueOf(char[] character)
static String valueOf(boolean b)
static String valueOf(char c)
static String valueOf(int i)
static String valueOf(long l)
static String valueOf(float f)
static String valueOf(double d)

 

<< String Manipulation - 1

String Manipulation - 3>>

 

Home Java SCJP SCWCD Servlet Site map