In Java int and String conversion

int converted to a String

  • Use the static method of Integer
    • Integer.toString (int num); a null value will throw a NullPointerException
  • Use the static method of String
    • String.valueOf (int num); return null "null"
  • num + ""; produced two string objects, the slowest

String into int

  • Interger.parseInt (String str) static method does not produce objects
  • Integer.valueOf (String str) .intValue (); generating an object corresponding to a new Interger.valueOf (String str)
Published 46 original articles · won praise 0 · Views 1023

Guess you like

Origin blog.csdn.net/weixin_37680513/article/details/103492626