1. Replacement function of StringBuffer:
Public StringBuffer replace (int start, int end, String str):
2. Case Demo:
1 Packagecn.itcast_04;2 3 /*4 * Replacement function of StringBuffer:5 * Public stringbuffer replace (int start,int end,string str): Replace with str from start to end6 */7 Public classStringbufferdemo {8 Public Static voidMain (string[] args) {9 //creating a String buffer objectTenStringBuffer SB =NewStringBuffer (); One A //Add Data -Sb.append ("Hello"); -Sb.append ("World"); theSb.append ("Java"); -System.out.println ("SB:" +SB); - - //Public stringbuffer replace (int start,int end,string + //str): Replace with str from start to end - //need: I want to replace the world data with "Happy Holidays" +Sb.replace (5, 10, "Happy Holidays"); //Index contains 5,6,7,8,9 (contains left 5, does not contain the right ten) ASystem.out.println ("SB:" +SB); at } -}
Operation Result:
Java basics to strengthen the replacement of the stringbuffer of the 41:stringbuffer class