...

/

Built-in String and Array Methods

Built-in String and Array Methods

Learn to use popular built-in methods related to strings and arrays in Java.

Built-in methods for strings

Java provides various built-in methods for dealing with strings. These methods are collectively called string methods.

Note: All string methods return a new string without changing the original one.

There are numerous tasks related to strings that make it easy for programmers to perform routine tasks. This section will provide examples and results of some commonly used string methods.

The methods related to case change

These methods change the letter case of the text stored in a string (say, from lowercase to uppercase). Let’s use an example program to explore case changes.

  • The toLowerCase() method converts all characters in a string to lowercase.
  • The toUpperCase() method converts all characters in a string to uppercase.
Press + to interact
class Test
{
public static void main(String args[])
{
System.out.println("EDUCATIVE".toLowerCase());
System.out.println("educative".toUpperCase());
}
}

The search-related methods

These methods search for the occurrence of text in a string. Let’s use an example program to explore searches.

  • The equals() method compares two strings and returns true if both strings are equal.
  • The endsWith()
...
Access this course and 1400+ top-rated courses and projects.