Java - Write code to set First Char of a string

Requirements

Write code to set First Char of a string

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String string = "book2s.com";
        String firstChar = "B";
        System.out.println(setFirstChar(string, firstChar));
    }//from  w w w  .  ja va 2s . c  o  m

    public static String setFirstChar(String string, String firstChar) {
        StringBuilder builder = new StringBuilder(string);

        builder = builder.deleteCharAt(0);
        builder.insert(0, firstChar);

        return builder.toString();
    }
}