Java??StringBuilder????????÷????
???????????? ???????[ 2015/12/9 15:59:08 ] ??????????????? ????? ???????
????????StringBuilder???????????????????????????StringBuilder????????????????StringBuffer???????????????????????????
????????Щ????????????????????????飺
????1. Java???????????StringBuilder??Ч???????
????2. StringBuilder???????????????“???”??????????StringBuffer??
????3. ???????????????????????????????slf4j????
????1. ???????????????????Ρ?
????StringBuilder??????????char[]?? ?????append()????????char[]????????????
????new StringBuilder() ?char[]??????????16?????????append??17????????????
??????System.arraycopy??????????????????
??????????????????????????????????char[]????????????GC???????????????129?????????????????????16??32??64?? 128??ε???????????????????496????????飬????????????£????????????
???????????????????????????????
?????????????????????????????????????????????16??????????????????????á?
????2. Liferay??StringBundler??
????Liferay??StringBundler?????????????????????·??????append()?????????????char[]?????????????????????String[]??????????????????????????String??length???????????????????????StringBuilder??
????3. ??????????????????char[]
??????????????????StringBuilder.toString()
????// Create a copy?? don't share the array
????return new String(value?? 0?? count);
????String????????????? System.arraycopy()???????????char[]??????????????????????????????????StringBuilder???char[]???????????????
?????????????Щchar[]????????????Unsafe?????????????????????????String??char[]??count????????????????????????
??????????????Щ?????????StringBuilder??????????????????????????????????????????????????????????????????
????4. ????StringBuilder
????????????????JDK???BigDecimal????????JDK?????????????SpringSide???????????StringBuilderHolder????????????????
????public StringBuilder getStringBuilder() {
????sb.setLength(0);
????return sb;
????}
????StringBuilder.setLength()?????????????count?????char[]?????????????toString()????????count???????????????String??????????????????????????????С?????????????????????StringBuilder????????????????
????????????????????Holder??????ThreadLocal?????д????BigDecimal??StringBuilderHolder??????
????5. ?? ?? StringBuilder
????String s ?? “hello ” + user.getName();
????????侭??javac??????Ч???????????????StringBuilder????????趨?????
????String s ?? new StringBuilder().append(“hello”).append(user.getName());
????????????????????????
????String s ?? “hello ”;
????// ?????????Щ???
????s = s ?? user.getName();
???????????????????????μ?StringBuilder??????????????StringBuilder???????????????????????????????s+=i; ??????????
??????R??????????JVM??????????????????Σ? ????+XX:+OptimizeStringConcat(JDK7u40??????)?????????(?м????????????) StringBuilder????????????????3????
????????????????????????????StringBuilder???趨????????
????6. StringBuffer ?? StringBuilder
????StringBuffer??StringBuilder????????AbstractStringBuilder??????????StringBuffer??????????synchronized??????
??????Щ?StringBuffer “???”???????????????????????????append???StringBuffer???????????
????7. ?????????????????????slf4j
????logger.info("Hello {}"?? user.getName());
??????????????????????????????slf4j???????????????????????????????
????????????????????????????????StringBuilder?????????????slf4j?????????????????indexof(“{}”)?? ?????subString()??????????StringBuilder???????????????????
????PS. slf4j?е?StringBuilder????Message????????50??????????????????????????50???????????????……????StringBuilder???????á?
????8. С??
????StringBuilder????д???????129?????????????????????625????????顣??????????????£??????????????ThreadLocal ???????StringBuilder?????????????????????3??????????
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11