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.mzph.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;然后做备份数…