Call to 'substring' is redundant

call for in a sentence
call to action
call to html
calls for a party
call up
call online
phone call synonym
call into meaning

I've created simple code to reverse an equation, but two lines are highlighted by lint in IntelliJ IDEA. Exact message is

Call to 'substring' is redundant

final String equation = "20+3*475-2-1*4";

final int size = equation.length();
final StringBuilder sb = new StringBuilder(size);
int right = size;
for (int i = size - 1; i > -1; i--) {
    switch (equation.charAt(i)) {
        case '+': case '-': case '*':
            sb.append(equation.substring(i + 1, right));  // this line
            sb.append(equation.charAt(i));
            right = i;
    }
}
if (right != 0) {
    sb.append(equation.substring(0, right));   // and this line
}

I haven't ever faced with a situation when lint highlights something without a reason. But now have no idea why these calls are redundant.

You can simplify the call to this:

sb.append(equation, i + 1, right);

This avoids an explicit intermediate string construction, allowing the implementation to copy the desired part of "equation" directly.

Call, Synonyms for call to at Thesaurus.com with free online thesaurus, antonyms, and definitions. Find descriptive alternatives for call to. call to. call to (someone) To shout to someone in an attempt to draw attention to oneself. I called to my best friend when I saw her walking down the street, but she had headphones on and couldn't hear me.

That's because StringBuilder append is overlaoded with a function, that also takes start and end index like substring.

So instead of using

sb.append(equation.substring(i + 1, right)); 

you can just use

sb.append(equation, i + 1, right); 

Call to Synonyms, Call to Antonyms, (call for someone/something) to go somewhere and get someone or something in order to take them to another place. I'll call for you at eight. Has he called for  Synonyms for call to at Thesaurus.com with free online thesaurus, antonyms, and definitions. Find descriptive alternatives for call to.

A String is a CharSequence, and StringBuffer has an append() method taking exactly the same arguments as substring(). You can eliminate the call to substring().

CALL FOR (phrasal verb) definition and synonyms, call meaning: 1. to give someone or something a name, or to know or address someone by a particular name: 2. If…. Learn more. Call Free is a free wifi calling app with free call & free text & free call recording. You can make free call & text free & free call recording, send SMS message all in one app with Call Free. Make low-rate international calls, directly make free call to a real phone number, even if your contact don’t have Call Free. Get a unique personal US or Canadian phone number with Call Free. Easily

CALL, Call definition, to cry out in a loud voice; shout: He called her name to see if she was home. See more. Call to __ Answers. CodyCross is an addictive game developed by Fanatee. Are you looking for never-ending fun in this exciting logic-brain app? Each world has more than 20 groups with 5 puzzles each. Some of the worlds are: Planet Earth, Under The Sea, Inventions, Seasons, Circus, Transports and Culinary Arts.

Call, 2.1Cry out to (someone) in order to summon them or attract their attention. 'she heard Terry calling her'. no object 'I distinctly heard you call'. Definition of call. (2) : to demand presentation of (something, such as a bond or option) for redemption The bonds could be called 10 years after issue. c(1) : to describe correctly in advance of or without knowledge of the event : predict He called the upward trend of the stock market in February.

Call, Call to action (CTA) is a marketing term for any device designed to prompt an immediate response or encourage an immediate sale. A CTA most often refers to​  Pay for calls to mobile and landline numbers with Skype Credit or, if you call international numbers regularly, you could save even more with a subscription. Get support for calling phones. Discover all Skype's features.

Comments
  • The only answer mentioned that intermediate string won't be created
  • It avoids necessarily constructing an intermediate string. An implementation of StringBuilder could, if it wanted, construct a substring. Passing in the string and the indices leaves it up to the implementor to decide; doing the substring yourself takes away the opportunity to do it without the substring.
  • Checked with openjdk, re-worded anyway.