• Post Reply Bookmark Topic Watch Topic
  • New Topic

convert from Character (object) into char (primitive)  RSS feed

 
Duc Ta
Ranch Hand
Posts: 46
2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,
Is there any method to convert a Character object in to a char primitive like parseLong() method conver a Long into long, parseInt() method convert an Integer in to integer?
Can anyone explain to me

Regards!
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Auto-boxing also works on Character / char, so you can just use assignment:

Note: Methods such as Long.parseLong() and Integer.parseInt() do not convert from Long to long or Integer to int, but from String to long or int. For converting from the wrapper type Long or Integer to the primitive type long or int, you can also use auto-unboxing, simply by assigning the value.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you been through the documentation for Character? It has methods for such interconversion explicitly without boxing and a constructor which might help.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Integer extends the Number class and the Number class has methods for getting most of the primitive number types from the object. Note that such methods may use casts, so the values returned may be different from the original.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!