java的equals方法_Java LocalDateTime类| 带示例的equals()方法

java的equals方法

LocalDateTime类equals()方法 (LocalDateTime Class equals() method)

  • equals() method is available in java.time package.

    equals()方法在java.time包中可用。

  • equals() method is used to check whether this date-time and the given object are equal or not.

    equals()方法用于检查此日期时间和给定对象是否相等。

  • equals() method 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.

    equals()方法是一种非静态方法,仅可通过类对象访问,如果尝试使用类名访问该方法,则会收到错误消息。

  • equals() method does not throw an exception at the time of comparing two objects.

    在比较两个对象时, equals()方法不会引发异常。

Syntax:

句法:

    public boolean equals(Object o);

Parameter(s):

参数:

  • Object o – represents the object is to be compared to this object.

    对象o –表示要与该对象进行比较的对象。

Return value:

返回值:

The return type of this method is boolean, it returns true when both the compared objects are equal otherwise it returns false.

此方法的返回类型为boolean ,当两个比较对象相等时返回true,否则返回false。

Example:

例:

// Java program to demonstrate the example 
// of boolean equals(Object o) method 
// of LocalDateTime
import java.time.*;
public class EqualsOfLocalDateTime {
public static void main(String args[]) {
// Instantiates two LocalDateTime
LocalDateTime da_ti1 = LocalDateTime.parse("2005-10-05T10:10:10");
LocalDateTime da_ti2 = LocalDateTime.now();
// Display da_ti1, da_ti2
System.out.println("LocalDateTime da_ti1 and da_ti2: ");
System.out.println("da_ti1: " + da_ti1);
System.out.println("da_ti2: " + da_ti2);
System.out.println();
// Here, this method compare this date-time
// to the given object for equality
// i.e. it returns false because both
// objects date and time are not same
boolean status = da_ti1.equals(da_ti2);
// Display status
System.out.println("da_ti1.equals(da_ti2): " + status);
// Here, this method compares this date-time
// to the given object for equality
// i.e. it returns true because both 
// objects date and time are same
status = da_ti1.equals(da_ti1);
// Display status
System.out.println("da_ti1.equals(da_ti1): " + status);
}
}

Output

输出量

LocalDateTime da_ti1 and da_ti2: 
da_ti1: 2005-10-05T10:10:10
da_ti2: 2020-06-04T08:41:24.891685da_ti1.equals(da_ti2): false
da_ti1.equals(da_ti1): true

翻译自: https://www.includehelp.com/java/localdatetime-equals-method-with-example.aspx

java的equals方法

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/541853.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

portlet java_Java Portlet 规范概述

前言1、portlet是一种类似servlet的规范。2、servlet是web组件,portlet也是web组件。参考1、百度百科:portlethttp://baike.baidu.com/link?urlvMzVwpkf5WzOL23GLkgM4C5C7Sarqh1XXShS73L7k-MbGgM0ooZ4Dl2Efor3bb4tZmmLo6v-muG5UW7_CYMTUahttp://hintcnu…

Java LocalDate类| minusWeeks()方法与示例

LocalDate类minusWeeks()方法 (LocalDate Class minusWeeks() method) minusWeeks() method is available in java.time package. minusWeeks()方法在java.time包中可用。 minusWeeks() method is used to subtract the given weeks from this LocalDate and return the LocalD…

Android推荐的几本书

2019独角兽企业重金招聘Python工程师标准>>> 第一阶段 <<第一行代码Android>><<疯狂Android>>第二阶段 <<Android开发艺术探索>><<Android群英传>>Android源码 第三阶段 <<Android开发艺术探索>><&…

java数据类型后缀_java基础知识---基本数据类型

1)四种整数类型(byte、short、int、long)&#xff1a;byte&#xff1a;8 位&#xff0c;用于表示最小数据单位&#xff0c;如文件中数据&#xff0c;-128~127short&#xff1a;16 位&#xff0c;很少用&#xff0c;-32768 ~ 32767int&#xff1a;32 位、最常用&#xff0c;-2^3…

duration java_Java Duration类| minusMillis()方法与示例

duration java持续时间类minusMillis()方法 (Duration Class minusMillis() method) minusMillis() method is available in java.time package. minusMillis()方法在java.time包中可用。 minusMillis() method is used to subtract the given duration in milliseconds from t…

Thread 和 Runnable创建新线程的区别,Runnable可以共享线程类的实例属性

Thread实现多线程&#xff1a; public class Thread2 extends Thread{ public int i; public void run(){ for(; i < 100 ;i) { System.out.println(getName() " " i); } } public static void main(String[] args){ for (int j 0; j < 100; j) { System…

java编程求最小公约数_java求最大公约数与最小公倍数

public class Gongyueshu{public static void main(String[] args){//从控制台输入两个数据int m Integer.parseInt(args[0]);int n Integer.parseInt(args[1]);int y 1 ;int b 1;if (m > 0 && n >0){//先判定这两个数是否为倍数关系&#xff0c;如果是则小数…

tdr上升时间什么设定_TDR的完整形式是什么?

tdr上升时间什么设定TDR&#xff1a;时域反射仪/车票寄存收据/定期存款收据 (TDR: Time Domain Reflectometer/ Ticket Deposit Receipt/ Term Deposit Receipt) 1)TDR&#xff1a;时域反射仪 (1) TDR: Time Domain Reflectometer) TDR is an abbreviation of the "Time D…

【java】反射+poi 导出excel

2019独角兽企业重金招聘Python工程师标准>>> 反射 导出的数组转变成对象 private static Object expexcelMaptobean(Class<?> cobj,Map<String,String> map,int[] expColums,String[] params) throws InstantiationException, IllegalAccessException…

css设置背景图片大小_如何使用CSS设置背景图片大小?

css设置背景图片大小Introduction: 介绍&#xff1a; As we all know that the images are a very responsive yet very creative way to display your web page or website to the users. The images also play a major role in indulging users to websites or web pages. T…

java gc的特性_Java12新特性 -- 可中断的G1 Mixed GC

Java 12 中增强了 G1 垃圾收集器关于混合收集集合的处理策略&#xff0c;这节主要介绍在 Java 12 中同时也对 G1垃圾回收器进行了改进&#xff0c;使其能够在空闲时自动将 Java 堆内存返还给操作系统&#xff0c;这也是 Java 12 中的另外一项重大改进。目前 Java 11 版本中包含…

在Python3中将字符串转换为字节的最佳方法

To convert a string to bytes, there are more than one way, 要将字符串转换为字节&#xff0c;有多种方法&#xff0c; Approach 1: use encode() method 方法1&#xff1a;使用encode()方法 test_str "include_help"print(type(test_str))test_bytes test_st…

【Java】PMD规则学习(1) --字符串比较

PMD是一款采用BSD协议发布的Java程序代码检查工具。该工具可以做到检查Java代码中是否含有未使用的变量、是否含有空的抓取块、是否含有不必要的对象等。该软件功能强大&#xff0c;扫描效率高&#xff0c;是Java程序员debug的好帮手。 PMD支持的编辑器包括&#xff1a;JDevelo…

php定义object数据类型,PHP数据类型(4):对象object

//创建一个类class Student{//定义属性public $name XuGZh;public $age 20;public $sex 男;//定义方法public function getInfo(){//当前对象中访问自己属性用伪变量$thisreturn my name:.$this->name..my age:.$this->age..my sex:.$this->sex;}}对象初始化:要创建…

avr计数_使用8位LCD创建计数器| AVR

avr计数This type of counter may be also used in the EVM machines. A counter can be used to count the number of times a button is pressed. It can have many applications. The most widely used counter application is in EVM and also in customer feedback machin…

php将字符变为数字,数字字符怎么转化为数字 php 怎么将字符转成数字

java中&#xff0c;String字符串转化为数字我现在想把一个String字符串转化为数字&#xff0c; String s"00000123" 我直接使java中String字符串转化为数字&#xff1a; 转换为浮点型&#xff1a; 使用Double或者Float的parseDouble或者parseFloat方法进行转换 Strin…

用U盘作为启动盘做系统步骤

步骤一&#xff1a;BIOS设置U盘启动 制作好Win10 U盘系统安装盘之后&#xff0c;我们需要在电脑的BIOS设置中把第一启动设备设置为U盘&#xff0c;设置后就可以从我们制作的Win10 U盘系统安装盘启动&#xff0c;从而显示系统安装界面开始安装系统。BIOS设置U盘启动的方法如下&a…

使用tkinter模块在Python中进行GUI编程

GUI (Graphical User Interface): GUI(图形用户界面)&#xff1a; GUI is a simple application which helps the user to interact with the computer or any other electronic device through a graphical icon. This used to perform different tasks on a desktop or lapt…

php轻博客社区视频教程,轻博客主题 - SEO极致优化的ZBLOG轻博客主题

zblog自适应轻博客主题&#xff0c;简洁、轻巧、极致优化~QQ群&#xff1a;457320274 (问题反馈以及其他链接交换等) 交流社区&#xff1a;https://www.bxiu.net/ (有问题可以求助交流)更新记录&#xff1a;2021.02.22 v2.8 更新内容&#xff1a;1、新增分类自定义标题&#xf…

Composer学习之————Ubuntu14.04下安装Composer

下载Composer&#xff1a; curl -sS https://getcomposer.org/installer | php 安装Composer&#xff1a; /usr/bin/php composer.phar --version 设置全局命令&#xff1a; sudo mv composer.phar /usr/local/bin/composer 查看是否安装与设置成功&#xff1a; composer -vers…