Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert String and int in Android

2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Editor to share with you how to convert String and int in Android. I hope you will get something after reading this article. Let's discuss it together.

First, how to convert the string String to integer int?

Method 1:

Int I = Integer.parseInt ([String]); or I = Integer.parseInt ([String], [int radix])

Method 2:

Int I = Integer.valueOf (my_str). IntValue (); what's the difference between the two methods? Is the effect the same? Is it interchangeable under any circumstances?

Method 1:

/ / using static methods directly will not result in redundant objects, but will throw an exception I = Integer.parseInt (s)

Method 2:

/ / Integer.valueOf (s) is equivalent to new Integer (Integer.parseInt (s)) and will also throw an exception, but it will produce an extra object I = Integer.valueOf (s) .intValue ()

Note: the methods of converting strings to Double, Float and Long are more or less the same.

Second, how to convert integer int to string String?

Method 1:

String s = String.valueOf (I)

Method 2:

String s = Integer.toString (I)

Method 3:

String s = "" + I; what's the difference between the two methods? Is the effect the same? Is it interchangeable under any circumstances?

Method 1:

/ / two String objects will be generated, s = I + ""

Method 2:

/ / directly use the static method of the String class and produce only one object s = String.valueOf (I)

Note: the methods of converting Double, Float and Long into strings are more or less the same.

After reading this article, I believe you have a certain understanding of "how to convert String and int in Android". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report