- package practice;
- import java.util.ArrayList;
- import java.util.Collection;
- public class String_StringBuffer {
- public static void main(String[] args) {
- // StringBuffer的定义格式:
- /*
- * StringBuffer sb = new StringBuffer("young");
- * sb.append("025");//append追加的字符包含在本身的16个字符内。
- * System.out.println(sb.reverse()); System.out.println(sb.capacity());
- * System.out.println(sb.charAt(5));//为什么打出的是U?reverse会改变原字符串
- * System.out.println(sb.indexOf("u"));
- *
- * System.out.println(sb.insert(2, "669"));
- */
- Collection<String> c = new ArrayList<String>();
- c.add("hellowoeld");
- System.out.println(c);
- c.add("hellojava");
- Object[] s = c.toArray();//为什么这里用String接收并强转会报错呢?无视了泛型
- //而用object就可以接收并且直接打印出字符串
- System.out.println( s [0]instanceof String);
- for (Object m : s) {
-
- System.out.println(m);
- }
- }
- }
复制代码 |
|