Java 定义多个单词的字符序列?

Java 定义多个单词的字符序列?,java,charsequence,Java,Charsequence,上面的代码成功地将listOfWords定义为:“word” 但是我需要listOfWorlds中有很多单词,而不仅仅是一个“word” 上面的代码是我想要的,但显然不正确 我希望能够调用listOfWords,并将其定义为“word”或“secondword”。CharSequence这里的变量是否正确?有什么帮助吗 您最好使用字符串列表。作为参考,您可以看到String实现CharSequence CharSequence listOfWords = ("word")("secondword

上面的代码成功地将
listOfWords
定义为:“
word
” 但是我需要
listOfWorlds
中有很多单词,而不仅仅是一个“
word

上面的代码是我想要的,但显然不正确


我希望能够调用
listOfWords
,并将其定义为“word”或“secondword”。
CharSequence
这里的变量是否正确?有什么帮助吗

您最好使用字符串列表。作为参考,您可以看到
String
实现
CharSequence

CharSequence listOfWords = ("word")("secondword");
publicstaticvoidmain(字符串eth[]){
List listOfWords=new ArrayList();
添加(“单词”);
添加(“第二个单词”);
添加(“第三个单词”);
//您使用的列表如下所示
System.out.println(listOfWords.get(0));//.get(0)获取列表中的第一个单词
System.out.println(listOfWords.get(1));//.get(1)获取列表中的第二个单词
System.out.println(listOfWords.get(2));//.get(2)获取列表中的第三个单词
}
结果:


A
CharSequence
是一个字符序列,如其名称所示;它不会“存储”单词。另外,如果你仔细看一看,你会发现1。这个接口的方法已经告诉你了,2
String
implements
CharSequence
@Tom Copy&Paste是一件可怕的事情:-)。。。谢谢
CharSequence listOfWords = ("word")("secondword");
public static void main(String eth[]) {
    List<String> listOfWords = new ArrayList<>();
    listOfWords.add("word");
    listOfWords.add("secondWord");
    listOfWords.add("thirdWord");

    // You use your list as followed
    System.out.println(listOfWords.get(0)); // .get(0) gets the first word in the List
    System.out.println(listOfWords.get(1)); // .get(1) gets the second word in the List
    System.out.println(listOfWords.get(2)); // .get(2) gets the third word in the List
}