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));
    }/*from   ww w.  j  av a 2  s.  co m*/

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

Related Exercise