日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

Java Integer类toString()方法与示例

發(fā)布時間:2025/3/11 java 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Java Integer类toString()方法与示例 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

Syntax:

句法:

public String toString();public static String toString(int value);public static String toString(int value, int radix's);

整數(shù)類toString()方法 (Integer class toString() method)

  • toString() method is available in java.lang package.

    toString()方法在java.lang包中可用。

  • toString() method is used to represent String denoted by this Integer object.

    toString()方法用于表示由此Integer對象表示的String。

  • toString(int value) method is used to represent String denoted by the given argument of int type.

    toString(int value)方法用于表示由int類型的給定參數(shù)表示的String。

  • toString(int value, int radix's) method is used to represent String of the given argument of int type in the radix's given by the second argument.

    toString(int value,int radix's)方法用于表示第二個參數(shù)給定的基數(shù)中int類型的給定參數(shù)的String。

  • These methods don't throw an exception at the time of String representation.

    這些方法在String表示時不會引發(fā)異常。

  • These are non-static methods, they are accessible with the class object only and if we try to access the method with the class name then we will get an error.

    這些是非靜態(tài)方法,只能通過類對象訪問,如果嘗試使用類名稱訪問該方法,則會收到錯誤消息。

Parameter(s):

參數(shù):

  • In the first case toString(), we don't pass any parameter or value.

    在第一種情況下, toString() ,我們不傳遞任何參數(shù)或值。

  • In the second case toString(int value), we pass only one parameter of the int type it represents the int value to be converted.

    在第二種情況下, toString(int value) ,我們僅傳遞一個int類型的參數(shù),它表示要轉(zhuǎn)換的int值。

  • In the third case toString(int value, int radix's), we pass two parameters of int type it represents the int value to be converted and the parameter radix's represents the radix to be used in String denotation.

    在第三種情況toString(int value,int radix's)中 ,我們傳遞了兩個int類型的參數(shù),它表示要轉(zhuǎn)換的int值,而參數(shù)radix's表示要在String表示法中使用的基數(shù)。

Return value:

返回值:

In the first case, the return type of this method is String - it returns the String representation of this Integer object.

在第一種情況下,此方法的返回類型為String-它返回此Integer對象的String表示形式。

In the second case, the return type of this method is String - it returns the String representation of the given argument is of int type.

在第二種情況下,此方法的返回類型為String-它返回給定參數(shù)的String表示形式為int類型。

In the third case, the return type of this method is String - it returns the String representation of the given argument is of int type in the given radix.

在第三種情況下,此方法的返回類型為String-它返回給定參數(shù)的String表示形式為給定基數(shù)的int類型。

Example:

例:

// Java program to demonstrate the example // of toString () method of Integer classpublic class ToStringOfIntegerClass {public static void main(String[] args) {// Object initializationInteger ob1 = new Integer(100);Integer ob2 = new Integer(200);// Display ob1,ob2 valuesSystem.out.println("ob1:" + ob1);System.out.println("ob2:" + ob2);// It represents the string of this Integer objectString value1 = ob1.toString();// It represents the string of the given integer parameterString value2 = Integer.toString(ob2);// It represents the string of the given integer parameter with radix 20String value3 = Integer.toString(ob2, 20);// Display result valuesSystem.out.println("ob1.toString(): " + value1);System.out.println("Integer.toString(ob2): " + value2);System.out.println("Integer.toString(ob2,20): " + value3);} }

Output

輸出量

ob1:100 ob2:200 ob1.toString(): 100 Integer.toString(ob2): 200 Integer.toString(ob2,20): a0

翻譯自: https://www.includehelp.com/java/integer-class-tostring-method-with-example.aspx

總結(jié)

以上是生活随笔為你收集整理的Java Integer类toString()方法与示例的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。