How to Remove the First Character in a String in Java

Suppose we want to remove the first character from the string coffee to create the word offee.

String str = "coffee"; // We want "offee"

In Java, we can use the substring() function to obtain any substring of a string.

As explained in the docs, we have two ways of using this method:

substring(int beginIndex)
substring(int beginIndex, int endIndex)

If we supply just one parameter, this method will return the substring from beginIndex (inclusive) to the end of the string.

str.substring(1); // "offee"