0

I'm curious if static methods of wrapper classes are really helpful.

Which of them are most useful and popularly used? Can you present any must-know tricks involving these methods?

Thanks in advance.

Maciej Ziarko
  • 11,494
  • 13
  • 48
  • 69

3 Answers3

1

Integer.parseInt(..) is used a lot. I don't have statistics though. I've used half of them, but of course they are all useful in certain contexts.

Bozho
  • 588,226
  • 146
  • 1,060
  • 1,140
1

The compare methods are useful to handle the primitive counterparts.

static int  compare(primitive p1, primitive p2) 
          Compares the two specified primitive values.

Possible use:

@Override
public int compareTo(MyClass other){
    return Double.compare(this.myDoubleField, other.myDoubleField);
}
Enno Shioji
  • 26,542
  • 13
  • 70
  • 109
0

Integer.toString(...) is used for turning an integer to string without resorting to "" + i.

Nikola
  • 694
  • 8
  • 15
  • You can also write `String.valueOf(...)` (which supposedly delegates to this method) - this works for every type, even for `null`. – Paŭlo Ebermann Mar 21 '11 at 02:48