Java - Write code to remove Prefix

Requirements

Write code to remove Prefix

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        String prefix = "b";
        System.out.println(removePrefix(str, prefix));
    }/*  w w w  .j  a  v a 2 s. c  om*/

    public static String removePrefix(String str, String prefix) {
        if (str.startsWith(prefix)) {
            return str.substring(prefix.length());
        }
        return str;
    }
}

Related Exercise