复制代码
- //:Stringer.java
- publicclassStringer{
- staticStringupcase(Strings){
- returns.toUpperCase();
- }
- publicstaticvoidmain(String[]args){
- Stringq=newString("howdy");
- System.out.println(q);//howdy
- Stringqq=upcase(q);
- System.out.println(qq);//HOWDY
- System.out.println(q);//howdy
- }
- }///:~
复制代码
- Strings="abc"+foo+"def"+Integer.toString(47);
复制代码
- //:ImmutableStrings.java
- //DemonstratingStringBuffer
- publicclassImmutableStrings{
- publicstaticvoidmain(String[]args){
- Stringfoo="foo";
- Strings="abc"+foo+
- "def"+Integer.toString(47);
- System.out.println(s);
- //The"equivalent"usingStringBuffer:
- StringBuffersb=
- newStringBuffer("abc");//CreatesString!
- sb.append(foo);
- sb.append("def");//CreatesString!
- sb.append(Integer.toString(47));
- System.out.println(sb);
- }
- }///:~
欢迎光临 仓酷云 (http://ckuyun.com/) | Powered by Discuz! X3.2 |