简体   繁体   English

String [] tempString = multipleValues.split(“-”); 但是int用于创建数组的格式String [] array = new String [10] ;?

[英]String[]tempString=multipleValues.split(“-”); but int the format for creating an array String[]array=new String[10];?

public void pushMany(String multipleValues){
String[]tempString=multipleValues.split("-");
for(int i=0;i<tempString.length;i++){
    push(tempString [i]);   
    }
}

I am used to creating arrays using String[]array=new String[10]; 我习惯于使用String [] array = new String [10]创建数组。 or creating multidimensional arrays such as String[]array={"car","truck"}; 或创建多维数组,例如String [] array = {“ car”,“ truck”}; Therefore, I am not sure what is going on with this??? 因此,我不确定这是怎么回事??? Is it still assigned an array? 它仍然分配一个数组吗?

String.split("-") function returns an array of Strings separated by "-". String.split("-")函数返回以“-”分隔的字符串数组。 Therefore yes it is assigned an array! 因此,是的,它分配了一个数组!

Refer to this link for more information. 有关更多信息,请参考此链接

The Javadoc is quite clear: Javadoc非常清楚:

[Returns] the array of strings computed by splitting this string around matches of the given regular expression [返回]通过将字符串拆分为给定正则表达式的匹配项而计算出的字符串数组

so yes, the value assigned to tempString is a String[] . 因此,是的,分配给tempString值为String[]

The String class has a method split String类具有方法拆分

public String[] split(String regex)

Quoting the java doc : 引用java doc

Splits this string around matches of the given regular expression. 围绕给定正则表达式的匹配项拆分此字符串。

This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. 该方法的工作方式就像通过调用具有给定表达式且限制参数为零的二参数拆分方法。

Trailing empty strings are therefore not included in the resulting array. 因此,结尾的空字符串不包括在结果数组中。

so when you do split("-") you are searching conincidences in the string that matches the "-" and the result is an array 因此,当您执行split("-")您正在搜索与“-”相匹配的字符串中的一致性,并且结果是一个数组

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

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