Brief Java Data Type Conversion - Select Blog from Yellow81

xiaoxiao2021-03-06  74

1 How to convert a string string into an integer int?

A. There are two ways:

1). INT i = integer.parseint ([string]); or i = integer.parseint ([String], [INT RADIX]);

2). INT i = integer.valueof (my_str) .intValue ();

Note: The string is transformed into Double, Float, and long.

2 How to convert integer int converted into a string string?

A. Have a variety of methods:

String s = String.Valueof (i);

2.) String s = integer.tostring (i);

3.) String s = "" i;

Note: Double, Float, long-converted to string is similar.

Java Data Type Conversion Ynniebo [Favorites] Keyword Type Conversion Source This is an example, saying that the data of data in Java is converted. For everyone to learn

package cn.com.lwkj.erts.register; import java.sql.Date; public class TypeChange {public TypeChange () {} // change the string type to the int type public static int stringToInt (String intstr) {Integer integer; integer = Integer.valueOf (intstr); return integer.intValue ();} // change int type to the string type public static String intToString (int value) {Integer integer = new Integer (value); return integer.toString () ;} // change the string type to the float type public static float stringToFloat (String floatstr) {Float floatee; floatee = Float.valueOf (floatstr); return floatee.floatValue ();} // change the float type to the string type public static String floatToString (float value) {Float floatee = new Float (value); return floatee.toString ();} // change the string type to the sqlDate type public static java.sql.Date stringToDate (String dateStr) { Return java.sql.date.valueof (datestr);} // change the sqldate type to the String TYPE PUBLIC STATIC STRING DATSTRING (Java.sql.date Datee) {Return Datee.toString ();

Public static void main (string [] args) {java.sql.date day; day = typechange.stringtodate ("2003-11-3"); string strDay = typechange.datetostring (day); system.out.println (strDay }}

Although the Data Type Conversion Function in Java can be found in the Java API, make a backup.

String-> Bytebyte Static Byte ParsebyTe (String S)

Byte-> String Byte Static String Tostring (byte B)

Char-> string character static string to string (char c)

String-> Short Short Static Short Parseshort (String S)

Short-> String Short Static String TSTRING (Short S)

String-> Integer Integer Static Int Parseint (String S)

Integer-> string integer static string toString (INT i)

String-> Long Long Static Long Parselong (String S)

Long-> String Long Static String Tostring (long i)

String-> float float static float parsefloat (string s)

FLOAT-> String float static string toString (float f)

String-> Double Double Static Double Parsedouble (String S)

Double-> StringDouble Static String Tostring (double

转载请注明原文地址:https://www.9cbs.com/read-95885.html

New Post(0)