Java - Write code to remove Start of a string


Write code to remove Start the start of a string

abc becomes bc


Use String.startsWith() method to check if the string is starting with another string.


public class Main {
  public static void main(String[] argv) {
    String str = "";
    String started = "book";
    System.out.println(removeStart(str, started));
  }/*from  ww  w . j  a va 2 s  .  c o m*/

  public static String removeStart(String str, String started) {
    if (isEmpty(str) || isEmpty(started))
      return str;
    return str.startsWith(started) ? str.substring(started.length()) : str;

  public static boolean isEmpty(String str) {
    return str == null || str.length() == 0;