简体   繁体   English

Java字符串拆分方法评估

[英]Java string split method evaluation

I need to parse an input string for an application and have a question related to how java evaluates the result of the string split() method. 我需要解析应用程序的输入字符串,并且有一个与java如何评估字符串split()方法的结果有关的问题。

For example, in the code bellow: 例如,在下面的代码中:

} else if (arg.equals("-multiplePaths")) {
    // Check if we have multiple paths 
    if (args[count++].contains(":")) {
    for(String tmpIDLPath : args[count-1].split(":"))
        m_includePaths.add(tmpIDLPath);
    } else {
        // Only one
        m_includePaths.add(args[count-1]);
    }

how is for loop evaluated? for循环如何评估? Is the split operation computed once for each iteration or once at the beginning? 拆分操作是为每个迭代计算一次还是在开始时计算一次?

The array you are looping over is computes once per loop. 您要遍历的数组每个循环计算一次。

BTW Your check is redundant. 顺便说一句,您的支票是多余的。

} else if (arg.equals("-multiplePaths")) {
    for(String tmpIDLPath : args[count-1].split(":"))
        m_includePaths.add(tmpIDLPath);

or 要么

} else if (arg.equals("-multiplePaths")) {
    Collections.addAll(m_includePaths, args[count-1].split(":"));

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

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