简体   繁体   English

为什么String Array不将字符串作为第一个索引

[英]why String Array did't tak a string as first Index

I have the following code. 我有以下代码。 There is problem in String[] sep2=strAdder; String[] sep2=strAdder;有问题String[] sep2=strAdder; compiler suggests that change the sep2 to String or change the type of strAdder to String[]. 编译器建议将sep2更改为String或将strAdder的类型更改为String []。 I am confused about that. 我对此感到困惑。 I think it should work 我认为应该可以

String strAdder = null;

while ((strLine = br.readLine()) != null )   {
    if (strLine.contains(">>")) {
        String[] sep1 = strLine.split(">>");
        String[] sep2 = strAdder;
        dd = null;
    }
    if (!(strLine.contains(">>"))) {
        strAdder.concat(strLine.toString());
    }
    i++;
}
in.close();

I don't understand what you are trying to do. 我不明白您要做什么。 strAdder is of type String , which means you can't assign it to String[] . strAdder的类型为String ,这意味着您不能将其分配给String[] Given that I don't know what you plan to do with sep2 then you could do String sep2 = strAdder or String[] sep2 = new String[]{strAdder} 鉴于我不知道您打算对sep2做什么,那么您可以执行String sep2 = strAdderString[] sep2 = new String[]{strAdder}

What is the i++ doing? i ++在做什么? Apart from that , your second if statement is nothing but the "else" of the previous if.Why have another if for that? 除此之外,您的第二个if语句就是前一个if的“ else”。为什么还要另外一个if? strLine is already a String why convert to string.And finally if you want to store just store "String sep2= strAdder;" strLine已经是一个String了,为什么要转换为string。最后,如果要存储,只需存储“ String sep2 = strAdder;”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM