gpt4 book ai didi

java - 将输入拆分为 vector

转载 作者:行者123 更新时间:2023-12-01 17:26:08 29 4
gpt4 key购买 nike

我必须将文件中的输入拆分为 vector 并添加到 vector 中。

文件输入

    1,375,seller
1,375,sellers
1,375,send
1,375,sister
1,375,south
1,375,specific
1,375,spoiler
1,375,stamp
1,375,state
1,375,stop
1,375,talked
1,375,tenant
1,375,today
1,375,told

FileInputStream fstream = new FileInputStream("e://inputfile.txt");
// Use DataInputStream to read binary NOT text.
BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
String strLine;

while ((strLine = br.readLine()) != null)
{
Vector dataPoints = new Vector();
dataPoints.add(br);


dataPoints.add(new DataPoint());
}


------ public DataPoint(double x, double y, String name) this is the method

如何将字符串拆分为 double 和 string 并将输入提供给 vector ?

最佳答案

使用String#split(String) :

Vector<DataPoint> dataPoints = new Vector<DataPoint>();        
while ((strLine = br.readLine()) != null) {
String[] array = strLine.split(",");
dataPoints.add(new DataPoint(Double.parseDouble(array[0]), Double.parseDouble(array[1]), array[2]));
}

关于java - 将输入拆分为 vector ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14857760/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com