可能重复:
声明未知大小的数组
我正在使用Java,我正在尝试将一个句子输入到字符串数组中.我正在对它进行标记并确定字数.但是,我需要将每个单词添加到字符串数组中,以确定是否存在重复项.如果我不知道单词计数直到程序后期,我不知道如何初始化我的数组.
//Declares variables
Scanner scan = new Scanner (System.in);
int withoutdup = 0, wordCount = 0;
String line, word;
StringTokenizer tokenizer;
List<String> sentence = ArrayList<String>;
//Asks user for input
System.out.println ("Please enter text. Enter DONE to finish.");
line = scan.next();
//Tokenizes the string and counts the number of character and words
while (!line.equals("DONE"))
{
tokenizer = new StringTokenizer (line);
while (tokenizer.hasMoreTokens())
{
word = tokenizer.nextToken();
wordCount++;
sentence += word;
}
line = scan.next();
}
Run Code Online (Sandbox Code Playgroud) 您可以使用什么方法在Java中进行基数转换?它类似于IntegerToBase(int,base),但我不记得了.