Java布爾類toString()方法及示例

Syntax:

句法:

    public String toString();
public static String toString(boolean value);

布爾類toString()方法 (Boolean class toString() method)

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

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

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

    toString()方法用于表示此布爾對象表示的String。

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

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

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

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

  • toString() is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.

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

  • toString(boolean value) is a static method, it is accessible with the class name too and, if we try to access these methods with the class object then also we will not get an error.

    toString(boolean value)是一個靜態方法,也可以使用類名進行訪問,并且,如果我們嘗試使用類對象訪問這些方法,那么我們也不會收到錯誤。

Parameter(s):

參數:

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

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

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

    在第二種情況下toString(boolean value) ,我們僅傳遞一個布爾類型的參數,它表示要轉換的布爾值。

Return value:

返回值:

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

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

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

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

Note: If this Boolean object value is true, it returns the desired string true. Else, if this Boolean object value is not equal to true, it returns the desired string false.

注意:如果此布爾對象的值為true ,則返回所需的字符串true 。 否則,如果此布爾對象值不等于true ,它將返回所需的字符串false

Example:

例:

// Java program to demonstrate the example 
// of toString() method of Boolean class
public class ToStringOfBooleanClass {
public static void main(String[] args) {
boolean b1 = true;
boolean b2 = false;
// Object initialization
Boolean ob1 = new Boolean(b1);
Boolean ob2 = new Boolean(b2);
// Display ob1,ob2 values
System.out.println("ob1:" + ob1);
System.out.println("ob2:" + ob2);
// It represents the string of this Boolean object
String value1 = ob1.toString();
// It represents the string of the given boolean parameter
String value2 = Boolean.toString(ob2);
// Display result values
System.out.println("ob1.toString(): " + value1);
System.out.println("Boolean.toString(ob2): " + value2);
}
}

Output

輸出量

ob1:true
ob2:false
ob1.toString(): true
Boolean.toString(ob2): false

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

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/379097.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/379097.shtml
英文地址,請注明出處:http://en.pswp.cn/news/379097.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

pcm數據編碼成為aac格式文件(可以在酷狗播放)

pcm數據編碼成為aac格式文件&#xff08;可以在酷狗播放&#xff09; 關于其中的aac adts格式可以參考&#xff1a;AAC ADTS格式分析 main.c #include <stdio.h> #include <stdlib.h> #include <stdlib.h>#include <libavcodec/avcodec.h> #include …

Python---實驗九

1、使用標準庫urllib爬取“http://news.pdsu.edu.cn/info/1005/31269.htm”平頂山學院新聞網上的圖片&#xff0c;要求:保存到F盤pic目錄中&#xff0c;文件名稱命名規則為“本人姓名” “_圖片編號”&#xff0c;如姓名為張三的第一張圖片命名為“張三_1.jpg”。 from re imp…

Request.Url學習(轉)

原文地址&#xff1a;http://www.cnblogs.com/jame-peng1028/articles/1274207.html?login1#commentform 網址&#xff1a;http://localhost:1897/News/Press/Content.aspx/123?id1#tocRequest.ApplicationPath/Request.PhysicalPathD:\Projects\Solution\web\News\Press\Con…

32接上拉5v_51單片機P0口上拉電阻的選擇

作為I/O口輸出的時候時&#xff0c;輸出低電平為0 輸出高電平為高組態(并非5V&#xff0c;相當于懸空狀態&#xff0c;也就是說P0 口不能真正的輸出高電平)。給所接的負載提供電流&#xff0c;因此必須接(一電阻連接到VCC)&#xff0c;由電源通過這個上拉電阻給負載提供電流。P…

[轉載]FPGA/CPLD重要設計思想及工程應用(時序及同步設計)

來源&#xff1a;http://www.eetop.cn/blog/html/11/317611-13412.html 數字電路中,時鐘是整個電路最重要、最特殊的信號。 第一, 系統內大部分器件的動作都是在時鐘的跳變沿上進行, 這就要求時鐘信號時延差要非常小, 否則就可能造成時序邏輯狀態出錯. 第二, 時鐘信號通常是系統…

duration java_Java Duration類| ofMinutes()方法與示例

duration javaDuration Class of Minutes()方法 (Duration Class ofMinutes() method) ofMinutes() method is available in java.time package. ofMinutes()方法在java.time包中可用。 ofMinutes() method is used to represent the given minutes value in this Duration. of…

實驗五 圖形設計

每復制一個方法都要綁定Paint事件 一、創建Windows窗體應用程序&#xff0c;要求如下&#xff1a;&#xff08;源代碼運行界面&#xff0c;缺少任一項為0分&#xff0c;源代碼只需粘貼繪制圖形代碼所在的方法&#xff0c;不用粘貼太多&#xff09; 例如: &#xff08;1&…

yuv編碼成h264格式寫成文件

yuv編碼成h264格式寫成文件 &#xff08;使用ffmpeg 編碼yuv420p編碼成h264格式&#xff09; #include <stdio.h> #include <stdlib.h> #include <stdint.h>#include <libavcodec/avcodec.h> #include <libavutil/time.h> #include <libavut…

c++ stl隊列初始化_聲明,初始化和訪問向量| C ++ STL

c stl隊列初始化Here, we have to declare, initialize and access a vector in C STL. 在這里&#xff0c;我們必須聲明&#xff0c;初始化和訪問C STL中的向量。 向量聲明 (Vector declaration) Syntax: 句法&#xff1a; vector<data_type> vector_name;Since, vec…

ADO.NET與SQL Server數據庫的交互

7.3.1 使用SqlConnection對象連接數據庫 例如&#xff1a;建立與SQL Server數據庫的連接。 string connstring"Data Sourceservername;uidusername;pwdpassword;Initial Catalogdbname";SqlConnection connnew SqlConnection(connstring);conn.Open(); 例如&#xf…

nsis 修改exe執行權限

通過修改注冊表的方式&#xff0c;修改exe的執行權限。&#xff0c;以下例子是使用管理員運行。 ;添加admin權限 SectionWriteRegStr HKCU "SOFTWARE\Microsoft\Windows NT\CurrentVersion\AppCompatFlags\Layers" "$INSTDIR\spp.exe" "RUNASADMIN&qu…

linux ftp日志_linux學習筆記(一)——Linux分區和目錄結構

linux學習筆記&#xff08;一&#xff09;——Linux分區和目錄結構安裝Linux時&#xff0c;手動掛載分區的情況下&#xff0c;/ 和 swap 是必須要掛載的&#xff0c;其他/home、/boot 等可以根據需要自行掛載。一般來說&#xff0c;簡單的話&#xff0c;建議掛載三個分區&#…

C#通過VS連接MySQL數據庫實現增刪改查基本操作

創建一個數據庫wsq 里面有一張beyondyanyu表 表里面有id(int)、names(varchar)、count(int)、passwords(varchar) 數據可以自己添 1、導入MySQL引用&#xff0c;你需要從官網或者其他地方下載&#xff0c;私聊我也可以 using MySql.Data.MySqlClient; 2、創建MySqlConnection對…

使用ffmpeg的filter處理yuv數據包括split filter(分流)、crop filter(裁剪)、vflip filter(垂直向上的翻轉)、overlay filter(合成)

使用ffmpeg的filter處理yuv數據包括split filter(分流)、crop filter(裁剪)、vflip filter(垂直向上的翻轉)、overlay filter(合成) #include <stdio.h>#include <libavcodec/avcodec.h> #include <libavformat/avformat.h> #include <libavfilter/avfil…

vc++ 6.0 堆棧_在C ++中使用鏈接列表實現堆棧

vc 6.0 堆棧To implement a stack using a linked list, basically we need to implement the push() and pop() operations of a stack using linked list. 要使用鏈接列表實現堆棧 &#xff0c;基本上&#xff0c;我們需要使用鏈接列表實現堆棧的push()和pop()操作。 Exampl…

煙雨小書店

煙雨小書店演示視頻 源碼

協議地址結構_TCP/IP 協議 講解

計算機網絡體系結構分層太厲害了&#xff0c;終于有人能把TCP/IP 協議講的明明白白了計算機網絡體系結構分層不難看出&#xff0c;TCP/IP 與 OSI 在分層模塊上稍有區別。OSI 參考模型注重“通信協議必要的功能是什么”&#xff0c;而 TCP/IP 則更強調“在計算機上實現協議應該開…

ffmpeg進行混音,將兩路音頻pcm數據合成一路輸出

ffmpeg進行混音&#xff0c;將兩路音頻pcm數據合成一路輸出 audiomixer.h #ifndef AUDIOMIXER_H #define AUDIOMIXER_H#include <map> #include <mutex> #include <cstdio> #include <cstdint> #include <string> #include <memory>exter…

python sep函數_Python中帶有print()函數的sep參數

python sep函數sep parameter stands for separator, it uses with the print() function to specify the separator between the arguments. sep參數代表分隔符&#xff0c;它與print()函數一起使用以指定參數之間的分隔符。 The default value is space i.e. if we dont us…

關于 MySQL 主從復制的配置(轉)

來源&#xff1a;http://www.oschina.net/bbs/thread/10388設置Mysql的主從設置很重要&#xff0c;有如下幾點用處&#xff1a;1 做備份機器&#xff0c;一旦主服務器崩潰&#xff0c;可以直接啟用從服務器作為主服務器2 可以直接鎖定從服務器的表只讀&#xff0c;然后做備份數…