小编use*_*178的帖子

如何声明未知大小的字符串数组?

可能重复:
声明未知大小的数组

我正在使用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 arrays string initialization

18
推荐指数
2
解决办法
7万
查看次数

API中用于在碱基之间转换的方法是什么?

您可以使用什么方法在Java中进行基数转换?它类似于IntegerToBase(int,base),但我不记得了.

java api integer base

5
推荐指数
2
解决办法
8368
查看次数

标签 统计

java ×2

api ×1

arrays ×1

base ×1

initialization ×1

integer ×1

string ×1