Skip to main content
Code Review

Return to Answer

replaced http://stackoverflow.com/ with https://stackoverflow.com/
Source Link
  • Instead of:

     currentSelectedDayLabel.setText("" + chooseDaySlider.getValue());
    

I'd use:

 currentSelectedDayLabel.setText(Integer.toString(chooseDaySlider.getValue()));

This creates just one String object (the result) instead of two (the empty and the resulting) and a StringBuilder object to append them.

See also the accepted answer the accepted answer of Java int to String - Integer.toString(i) vs new Integer(i).toString().

  • I'd use:

     String.format("You are %d%s old.", days, days == 1 ? "" : "s")
    

instead of string concatenation:

 "You are " + days + " day" + (days == 1 ? "" : "s") + " old."

This shows the structure of the resulting string and the parameter types at a glance.

  • Instead of:

     currentSelectedDayLabel.setText("" + chooseDaySlider.getValue());
    

I'd use:

 currentSelectedDayLabel.setText(Integer.toString(chooseDaySlider.getValue()));

This creates just one String object (the result) instead of two (the empty and the resulting) and a StringBuilder object to append them.

See also the accepted answer of Java int to String - Integer.toString(i) vs new Integer(i).toString().

  • I'd use:

     String.format("You are %d%s old.", days, days == 1 ? "" : "s")
    

instead of string concatenation:

 "You are " + days + " day" + (days == 1 ? "" : "s") + " old."

This shows the structure of the resulting string and the parameter types at a glance.

  • Instead of:

     currentSelectedDayLabel.setText("" + chooseDaySlider.getValue());
    

I'd use:

 currentSelectedDayLabel.setText(Integer.toString(chooseDaySlider.getValue()));

This creates just one String object (the result) instead of two (the empty and the resulting) and a StringBuilder object to append them.

See also the accepted answer of Java int to String - Integer.toString(i) vs new Integer(i).toString().

  • I'd use:

     String.format("You are %d%s old.", days, days == 1 ? "" : "s")
    

instead of string concatenation:

 "You are " + days + " day" + (days == 1 ? "" : "s") + " old."

This shows the structure of the resulting string and the parameter types at a glance.

added 301 characters in body
Source Link
Gerold Broser
  • 1.3k
  • 8
  • 20

Instead of:

currentSelectedDayLabel.setText("" + chooseDaySlider.getValue());
  • Instead of:

     currentSelectedDayLabel.setText("" + chooseDaySlider.getValue());
    

I'd use:

currentSelectedDayLabel.setText(Integer.toString(chooseDaySlider.getValue()));

This creates just one String object (the result) instead of two (the empty and the resulting) and a StringBuilder object to append them.

See also the accepted answer of Java int to String - Integer.toString(i) vs new Integer(i).toString().

  • I'd use:

     String.format("You are %d%s old.", days, days == 1 ? "" : "s")
    

instead of string concatenation:

 "You are " + days + " day" + (days == 1 ? "" : "s") + " old."

This shows the structure of the resulting string and the parameter types at a glance.

Instead of:

currentSelectedDayLabel.setText("" + chooseDaySlider.getValue());

I'd use:

currentSelectedDayLabel.setText(Integer.toString(chooseDaySlider.getValue()));

This creates just one String object (the result) instead of two (the empty and the resulting) and a StringBuilder object to append them.

See also the accepted answer of Java int to String - Integer.toString(i) vs new Integer(i).toString().

  • Instead of:

     currentSelectedDayLabel.setText("" + chooseDaySlider.getValue());
    

I'd use:

currentSelectedDayLabel.setText(Integer.toString(chooseDaySlider.getValue()));

This creates just one String object (the result) instead of two (the empty and the resulting) and a StringBuilder object to append them.

See also the accepted answer of Java int to String - Integer.toString(i) vs new Integer(i).toString().

  • I'd use:

     String.format("You are %d%s old.", days, days == 1 ? "" : "s")
    

instead of string concatenation:

 "You are " + days + " day" + (days == 1 ? "" : "s") + " old."

This shows the structure of the resulting string and the parameter types at a glance.

Source Link
Gerold Broser
  • 1.3k
  • 8
  • 20

Instead of:

currentSelectedDayLabel.setText("" + chooseDaySlider.getValue());

I'd use:

currentSelectedDayLabel.setText(Integer.toString(chooseDaySlider.getValue()));

This creates just one String object (the result) instead of two (the empty and the resulting) and a StringBuilder object to append them.

See also the accepted answer of Java int to String - Integer.toString(i) vs new Integer(i).toString().

lang-java

AltStyle によって変換されたページ (->オリジナル) /