具体的な詳細は次のとおりです。
int-> stringint i = 12345; string s = "";
最初の方法:s = i+"";
2番目の方法:s = string.valueof(i);
これら2つの方法の違いは何ですか?関数は同じですか?どんな状況でも交換できますか?
文字列 - > ints = "12345"; int i;
最初の方法:i = integer.parseint(s);
2番目の方法:i = integer.valueof(s).intvalue();
これら2つの方法の違いは何ですか?関数は同じですか?どんな状況でも交換できますか?
ここに答えがあります:
最初の方法:s = i+""; // 2つの文字列オブジェクトが生成されます
2番目の方法:s = string.valueof(i); //文字列クラスの静的方法を直接使用して、1つのオブジェクトのみを生成する
最初の方法:i = integer.parseint(s); //静的メソッドを直接使用すると、冗長オブジェクトは生成されませんが、例外はスローされます
2番目の方法:i = integer.valueof(s).intvalue(); // integer.valueof(s)は新しい整数(integer.parseint(s))に相当し、例外をスローしますが、もう1つのオブジェクトが生成されます。
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1文字列を整数intに変換する方法は?
A. 2つの方法があります。
1)。 int i = integer.parseint([string]);または
i = integer.parseint([string]、[int radix]);
2)。 int i = integer.valueof(my_str).intvalue();
注:文字列をダブル、フロート、ロングに変換する方法は似ています。
2整数intを文字列文字列に変換する方法は?
A. 3つの方法があります。
1.)string s = string.valueof(i);
2.)string s = integer.toString(i);
3.)string s = "" + i;
注:ダブル、フロート、長い弦を変換する方法は似ています。
Javaデータ型変換
これは、Javaのデータ数値タイプの変換を指す例です。誰もが学ぶために
パッケージShenmixiaozhu; Import java.sql.date; public class typechange {publiceChange(){} //文字列タイプをint typepepublic stringting(string intstr){integer integer; integer = integer.valueof); inttoString(int value){integer integer = new integer(value); return integer.tostring();} // string typepublic stringtofloat(string floatstr){float floate; floatee = float.valueof(floattr); return float.floatvalue Type}; Typepublic static string floattostring(float value){float float = new float(value); return floate.tostring();} // string typepepeppublic static java.sql.date stringtodate(string datesestr){return java.date.valueof(dat date atestres the the the the the the the the the the the the the shing the the the the the shing stringtodate) Typeepublic static String DateTostring(java.sql.date datee){return datee.tostring();} public static void main(string [] args){java.sql.date day; day = typechange.stringtodate( "2003-11-3"); String str = strna typechange.datetostring(day); system.out.println(strday);}}}上記のコンテンツは、編集者が紹介したINTと文字列タイプの変換の2つの方法です。私はそれがあなたを助けることができることを願っています。