Posted on 2009-07-12 15:03
WANGPENG 阅读(3201)
评论(1) 编辑 收藏 所属分类:
Java
1 package p1 ;
2
3 import java.util.ArrayList ;
4 import java.util.Iterator ;
5 import java.util.List ;
6
7 public class ListTest {
8 public String simpleFun(List<String> l) {
9 StringBuffer sb = new StringBuffer() ;
10
11 sb.append("[") ;
12
13 Iterator<String> i = l.iterator() ;
14 boolean isNull = i.hasNext() ;
15 while (isNull) {
16 String o = i.next() ;
17 sb.append(String.valueOf(o)) ;
18 isNull = i.hasNext() ;
19 if (isNull) {
20 sb.append(",") ;
21 }
22 }
23
24 sb.append("]") ;
25
26 return sb.toString() ;
27 }
28
29 public static void main(String[] args) {
30 List<String> arrList = new ArrayList<String>() ;
31 arrList.add("A") ;
32 arrList.add("B") ;
33 arrList.add("C") ;
34
35 ListTest lt = new ListTest() ;
36 String result = lt.simpleFun(arrList) ;
37 System.out.println(result) ;
38 }
39 }
40
结果:[A,B,C]