Home » Core Java » lang » String (page 3)

String

Compare Strings

In this example we shall show you how to compare Strings. We are using the methods that the String class provides. To compare Strings one should perform the following steps: Create two new String objects. Use the compareTo(String anotherString) to compare the two Strings. This method compares two strings lexicographically. The comparison is based on the Unicode value of each ...

Read More »

String replace method

With this example we are going to demonstrate how to use the replace method of String class. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. In short, to replace a String you should: Create a new String. Use replace(char oldChar, char newChar) API method. This method ...

Read More »

String trim method

This is an example of how to use the trim method of String class. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Trimming a String implies that you should: Create a new String. Use trim() method of String. This method returns a copy of the string, ...

Read More »

Convert String toLowerCase

In this example we shall show you how to convert a String to LowerCase. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. To convert a String to LowerCase one should perform the following steps: Create a new String. Use toLowerCase() API method of String. This method ...

Read More »

Convert String toUpperCase

With this example we are going to demonstrate how to convert a String to UpperCase. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. In short, to convert a String to UpperCase you should: Create a new String. Use toUpperCase() API method of String. This method converts ...

Read More »

String split method

This is an example of how to split a String. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Splitting a String implies that you should: Create a new String. Use the split(String regex) API method of String. This method splits this string around matches of the ...

Read More »

String startsWith method

In this example we shall show you how to use the startsWith method of String class. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. To check if a String starts with a specified prefix one should perform the following steps: Create a new String. Use startsWith(String ...

Read More »

String endsWith method

With this example we are going to demonstrate how to use the endsWith method of String. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. In short, to check if a String ends with a specified suffix you should: Create a new String. Use endsWith(String suffix) API ...

Read More »

Search String with indexOf method

This is an example of how to search a String using the indexOf method of String class. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. Searching a String implies that you should: Create a new String. Use indexOf(String str) API method of String. This method returns ...

Read More »

Convert String to char array

In this example we shall show you how to convert a String to char array. The String class represents character strings. All string literals in Java programs, such as "abc", are implemented as instances of this class. To convert a String to char array one should perform the following steps: Create a new String. Use toCharArray() API method of String. ...

Read More »