Java – removing first character of a string

Java – removing first character of a string

Use the substring() function with an argument of 1 to get the substring from position 1 (after the first character) to the end of the string (leaving the second argument out defaults to the full length of the string).

Jamaica.substring(1);
public String removeFirstChar(String s){
   return s.substring(1);
}

Java – removing first character of a string

Use substring() and give the number of characters that you want to trim from front.

String value = Jamaica;
value = value.substring(1);

Answer: amaica

Leave a Reply

Your email address will not be published.