You're wasting your time and making the code less clear. See here: http://c2.com/cgi/wiki?StringBuffer
This is why it is a bad idea to blindly follow the FindBugs report. [email protected] wrote: > Author: smartini > Date: Tue Nov 17 13:19:52 2009 > New Revision: 881271 > > URL: http://svn.apache.org/viewvc?rev=881271&view=rev > Log: > string concatenation improvement (as suggested by FindBugs) > > Modified: > > incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/ListViews.java > > Modified: > incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/ListViews.java > URL: > http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/ListViews.java?rev=881271&r1=881270&r2=881271&view=diff > ============================================================================== > --- > incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/ListViews.java > (original) > +++ > incubator/pivot/trunk/tutorials/src/org/apache/pivot/tutorials/lists/ListViews.java > Tue Nov 17 13:19:52 2009 > @@ -51,7 +51,7 @@ > } > > private void updateSelection(ListView listView) { > - String selectionText = ""; > + StringBuffer selectionText = new StringBuffer(""); > > Sequence<Span> selectedRanges = listView.getSelectedRanges(); > for (int i = 0, n = selectedRanges.getLength(); i < n; i++) { > @@ -61,15 +61,15 @@ > j <= selectedRange.end; > j++) { > if (selectionText.length() > 0) { > - selectionText += ", "; > + selectionText.append(", "); > } > > String text = (String)listView.getListData().get(j); > - selectionText += text; > + selectionText.append(text); > } > } > > - selectionLabel.setText(selectionText); > + selectionLabel.setText(selectionText.toString()); > } > }; > > > >
