为什么问这个单词出现多少次,为什么我总是得到138
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么问这个单词出现多少次,为什么我总是得到138相关的知识,希望对你有一定的参考价值。
我试图找出一个状态在一列csv文件中出现多少次。它也只打印一半的状态。我的代码如下
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Arrays;
public class csvtxt {
public static void main(String a[]){
StringBuilder sb = new StringBuilder();
String strLine = "";
List<String> list = new ArrayList<String>();
try {
BufferedReader br = new BufferedReader(new FileReader("C:\\Users\\dbb38\\Downloads\\customers_export_111 - customers_export_1 (1).csv"));
while (strLine != null)
{
strLine = br.readLine();
sb.append(strLine);
sb.append(System.lineSeparator());
strLine = br.readLine();
if (strLine==null)
break;
list.add(strLine);
}
//
String wordToSearchFor = "Alabama";
int Alabama = 0;
for(String Alabama1 : list)
{
if(Alabama1.equals(wordToSearchFor))
{
Alabama++;
}
}
System.out.println("Alabama = " + "["+ Alabama +"]");
//
String wordToSearchFor1 = "Alaska";
int Alaska = 0;
for(String Alaska1 : list)
{
if(Alaska1.equals(wordToSearchFor))
{
Alaska++;
}
}
System.out.println("Alaska = " + "["+ Alaska +"]");
//
String wordToSearchFor2 = "Arizona";
int Arizona = 0;
for(String Arizona1 : list)
{
if(Arizona1.equals(wordToSearchFor))
{
Arizona++;
}
}
System.out.println("Arizona = " + "["+ Arizona +"]");
//
System.out.println(Arrays.toString(list.toArray()));
br.close();
} catch (FileNotFoundException e) {
System.err.println("File not found");
} catch (IOException e) {
System.err.println("Unable to read the file.");
}
}
}
这里是我得到的输出。我切断了一些输出,因为95881的字符太多。
Alabama = [138]
Alaska = [138]
Arizona = [138]
[ South Dakota, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Tennessee, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Texas, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Utah, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Vermont, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia, Virginia]
应该有35个佛蒙特州的,但只打印其中的17个。任何帮助,将不胜感激!]
答案
替换
if(Arizona1.equals(wordToSearchFor))
with
if(Arizona1.equals(wordToSearchFor2))
您也需要对其他人进行类似的更改。看到你的错误了吗?
以上是关于为什么问这个单词出现多少次,为什么我总是得到138的主要内容,如果未能解决你的问题,请参考以下文章