List<String>转化成String

项目中很多时候需要对List<String>转化成String类型。参考代码如下:

List<String> stringList = new ArrayList<String>();
stringList = loginEntryServiceRest.loginentry(language);//通过函数调用得到List<String>的对象
StringBuilder result=new StringBuilder();//新建一个StringBuilder的对象
for (String string : stringList) {//通过StringBuilder或者StringBuffer可以在字符串中加入其它字符,可以用 stringList.toString()直接得到,不过这样不能加入字符
result.append("\\");
result.append(string);
}
String a = result.toString();

}

在项目中其它的类型转换与List的方式类似,都是菜鸟要掌握的基础。

List<AbstractSchema> schemas = schemaDAO.queryByLoginentry(attributableUtil
.schemaClass());
List<String> info=new ArrayList<String>();
for(AbstractSchema dis : schemas){
String displayname = dis.getDisplayName();
info.add(displayname);

}

posted @ 2015-10-08 16:43  cherry-tj  阅读(7306)  评论(0)    收藏  举报