解析向量字符串转换成字符串? [英] parse Vector string into a String?

查看:280
本文介绍了解析向量字符串转换成字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何能分析一个向量到正常字符串?

How can i parse a Vector to a normal String?

矢量newfollowerlist =1,名称2,NAME3,NAME4;

Vector newfollowerlist = "name1, name2, name3, name4";

一旦我输出的矢量字符串,它看起来像这样;

As soon i output the vector string it looks like this;

[name1, name2, name3, name4]

和我想删除[]行的,所以我想到了矢量字符串解析到一个
正常的字符串并删除[]是:

and i want to delete the [] of the line so i thought about parsing the vector string to a normal String and delete the [] by:

String stringWithoutArraySymbols = String VectorHolder.replaceAll("[",""); 
String stringWithoutArraySymbols = String VectorHolder.replaceAll("]","");

我怎样才能真正解析它还是有一个更简单的方法来做到这一点?

How can i actually parse it or is there an easier way to do this?

推荐答案

一个微小的变化

String s = newfollowerlist.toString();
System.out.println(s.substring(1, s.length()-1));

您知道 newfollowerlist.toString()的格式,因此它很容易得到你想要的格式。如果newfollowerlist是矢量,列表,设置或许多其他类型的集合应该工作。

You know the format of newfollowerlist.toString() so its easy enough to get your desired format. Should work if newfollowerlist is a Vector, List, Set or many other Collection types.

这篇关于解析向量字符串转换成字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆