打开csv集合和连续数组
我不太明白 opencsv 网站上给出的关于如何在此处使用集合列表的信息,例如:
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));**
List myEntries = reader.readAll();**
我尝试访问列表的成员,例如 System.out.println(myEntries.get(2)) 但它给了我类似
d1e604
的东西,当我测试元素是否存在时,
boolean b = myEntries.contains("the element");** and it returns false.
我需要做什么来访问标记化字符串?
通过使用 readNext(),元素由“\n”分隔,我想以连续的编号分配元素。的数组。
while((tokened = reader.readNext()) != null){
int numOfArray = tokened.length;
System.out.println("number of items:"+ numOfArray) ;
for (int i = 0;i < numOfArray;i++) {
System.out.println(" tokenNo[" + i + "]: " + tokened[i]);
}
}
i dont quite understand by the given eg on opencsv site on how to use collection here List,eg is:
CSVReader reader = new CSVReader(new FileReader("yourfile.csv"));**
List myEntries = reader.readAll();**
I tried accessing a member of the List for eg System.out.println(myEntries.get(2))
but it gives me something like d1e604
and when i tested for existence of an element
boolean b = myEntries.contains("the element");** and it returns false.
what do i need to do to access the tokenized Strings?
by using readNext(), the elements are separated by "\n" and i want to assign the elements in a continuous no. of array.
while((tokened = reader.readNext()) != null){
int numOfArray = tokened.length;
System.out.println("number of items:"+ numOfArray) ;
for (int i = 0;i < numOfArray;i++) {
System.out.println(" tokenNo[" + i + "]: " + tokened[i]);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为您错过了有关 CSV 的一些事实。 CSV 是关于行和列的。
readNext()
返回表示一行的字符串数组。所以我猜想,readAll()返回一个string[]列表。I think you missed a little fact about CSV. CSV is about lines AND columns.
readNext()
returns an array of strings representing a line. So I would guess, readAll() returns a list of string[].List myEntries 的每个元素都是一个 String[]。
即这是一个字符串数组。
这意味着你需要演员阵容。
另外 -
那是因为 toString 方法没有被正确覆盖。这是 Object 类中实现的 toString 方法的默认行为。
Each element of your List myEntries is a String[].
i.e. That is an array of String.
that means you need a cast.
Also -
That's because the toString method is not properly overridden. That's the default behavior of the toString method as implemented in the Object class.