3
\$\begingroup\$

I am reading hadoop source code , Here I have a doubt "org.apache.hadoop.util.StringUtils" they reassigned a list which is already intiailized.

  public static Collection<String> getStringCollection(String str){
    List<String> values = new ArrayList<String>();
    if (str == null)
      return values;
    StringTokenizer tokenizer = new StringTokenizer (str,",");
    values = new ArrayList<String>();
    while (tokenizer.hasMoreTokens()) {
      values.add(tokenizer.nextToken());
    }
    return values;
  }

Is there any reason to reassign here?

\$\endgroup\$
1
  • \$\begingroup\$ This question appears to be off-topic because it is not your own written code. \$\endgroup\$ Commented Jan 27, 2014 at 1:09

2 Answers 2

2
\$\begingroup\$

It looks like a useless reassignment. It must be some refactoring gone wrong. At worst, it will cause a tiny performance hit.

\$\endgroup\$
0
\$\begingroup\$

Yes you are right, but it will cause a tiny performance hit! and they should use String.split() instead of StringTokenizer.

\$\endgroup\$

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.