Java Byte類的compareTo()方法和示例

簡短的類compareTo()方法 (Short class compareTo() method)

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

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

  • compareTo() method is used to check equality or inequality for this Byte object against the given Byte object mathematically or in other words, we can say this method is used to compare two Byte objects.

    compareTo()方法用于在數學上檢查此Byte對象與給定Byte對象的相等性或不相等性,換句話說,可以說此方法用于比較兩個Byte對象。

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

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

  • compareTo() method does not throw an exception at the time of comparing Byte object.

    在比較Byte對象時, compareTo()方法不會引發異常。

Syntax:

句法:

    public int compareTo(Byte value2);

Parameter(s):

參數:

  • Byte value2 – represents the Byte object to compare with.

    字節值2 –表示要比較的字節對象。

Return value:

返回值:

The return type of this method is int, it returns an integer value based on the following cases,

此方法的返回類型為int ,它基于以下情況返回整數值:

  • It returns 0, if value1 is mathematically equal to value2.

    如果value1在數學上等于value2 ,則返回0

  • It returns the value < 0, if value1 is mathematically less than value2.

    如果value1在數學上小于value2 ,則返回值<0

  • It returns the value > 0, if value1 is mathematically greater than value2.

    如果value1在數學上大于value2 ,則返回值> 0

Example:

例:

// Java program to demonstrate the example 
// of compareTo(Byte value2) method of Byte class
public class CompareToOfByteClass {
public static void main(String[] args) {
// Variables initialization
byte b1 = 10;
byte b2 = 20;
// Byte instance 
Byte value1 = new Byte(b1);
Byte value2 = new Byte(b2);
// It compare two Byte objects and placed the result 
// in another variable (compare) of integer type
int compare = value1.compareTo(value2);
// Display result
System.out.println("value1.compareTo(value2): " + compare);
System.out.println();
if (compare == 0)
System.out.println("value1 is equal to value2");
else if (compare < 0)
System.out.println("value1 is less than value2");
else
System.out.println("value1 is greater than value2");
}
}

Output

輸出量

value1.compareTo(value2): -10value1 is less than value2

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

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

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

相關文章

顯示照片的RGB直方圖

顯示照片的RGB直方圖 import numpy as np import cv2 as cv from matplotlib import pyplot as plt img cv.imread(E:\Python-workspace\OpenCV\OpenCV/BEYOND.png,1)#第一個參數為選擇照片的路徑&#xff0c;注意照片路徑最后一個為正斜杠其他都為反斜杠&#xff1b;第二個參…

OUT還開通博客!

現在哪有人還在玩博客哦&#xff0c;哎試試&#xff0c;記錄一下自己開發網站的點滴吧&#xff01;轉載于:https://www.cnblogs.com/17say/archive/2013/02/18/2915125.html

網站V5的一些想法(轉)

V5即將到來&#xff0c;面對“全新”的V5&#xff0c;前端這塊自然也要借這次改版的機會&#xff0c;將我們前端的一些想法實踐到V5中去&#xff0c;實現一次跨越。 1 嘗試模塊化的代碼書寫(html、css等) 模塊化的目的是為了提高代碼的重用性、擴展性、可維護性 2 文件引用使用…

mysql慢查詢開啟語句分析_mysql慢查詢語句分析總結

我們經常會接觸到MySQL&#xff0c;也經常會遇到一些MySQL的性能問題。我們可以借助慢查詢日志和explain命令初步分析出SQL語句存在的性能問題通過SHOW FULL PROCESSLIST查看問題SHOW FULL PROCESSLIST相當于select * from information_schema.processlist可以列出正在運行的連…

P2P技術詳解(三):P2P中的NAT穿越(打洞)方案詳解(進階分析篇)

目錄1、NAT和NAPT2、NAT帶來的問題3、P2P通信穿越NAT的技術、方法4、NAT穿越技術1&#xff1a;應用層網關4.1、原理4.2、限制5、NAT穿越技術2&#xff1a;中間件技術5.1、原理5.2、限制6、NAT穿越技術3&#xff1a;打洞技術(Hole Punching)6.1、原理6.2、方法6.2.1NAT行為類型與…

Java BufferedReader reset()方法及示例

BufferedReader類的reset()方法 (BufferedReader Class reset() method) reset() method is available in java.io package. reset()方法在java.io包中可用。 reset() method is used to reset the stream to the most recent mark of this stream. reset()方法用于將流重置為該…

將兩大小完全相同的照片進行加權混合對比

將兩張大小完全相同的照片進行加權混合對比 import cv2 img1cv2.imread(E:\Python-workspace\OpenCV\OpenCV/water1.png,1)#第一個參數為選擇照片的路徑&#xff0c;注意照片路徑最后一個為正斜杠其他都為反斜杠&#xff1b;第二個參數&#xff0c;其中1表示所選照片為彩色照片…

過了很久了

很久沒來這里了&#xff0c;一般也就找找資料會上一下子。差不多算是荒廢了吧 不要緊&#xff0c;開始寫了轉載于:https://www.cnblogs.com/Anykong/archive/2013/02/18/2916333.html

古文中驚艷的句子

-1】終于為那一身江南煙雨覆了天下&#xff0c;容華謝后&#xff0c;不過一場&#xff0c;山河永寂。-2】千秋功名&#xff0c;一世葬你&#xff0c;玲瓏社稷&#xff0c;可笑卻無君王命。-3】鳳凰臺上鳳凰游&#xff0c;負約而去&#xff0c;一夜苦等&#xff0c;從此江南江北…

java 方法 示例_Java ArrayDeque pollFirst()方法與示例

java 方法 示例ArrayDeque類pollFirst()方法 (ArrayDeque Class pollFirst() method) pollFirst() Method is available in java.lang package. pollFirst()方法在java.lang包中可用。 pollFirst() Method is used to return the first element of the queue denoted by this d…

P2P技術詳解(四):P2P技術之STUN、TURN、ICE詳解

目錄1、內容概述2、STUN詳解2.1 RFC3489/STUN2.1.1 報文結構2.1.2實現原理2.1.3STUN功能舉例2.2 RFC5389/STUN2.2.1STUN用途2.2.2報文結構2.3 RFC5389與RFC3489的區別2.4 新特性介紹2.4.1指紋機制2.4.2通過DNS發現服務器機制2.4.3認證和消息完整性機制2.4.4備份服務器機制2.5 R…

比較兩張大小相同的照片的差異,返回數值

比較兩張大小相同的照片的差異&#xff0c;返回數值 from PIL import Image import math import operator from functools import reducedef image_contrast(img1, img2):image1 Image.open(img1)image2 Image.open(img2)h1 image1.histogram()h2 image2.histogram()resul…

poj2115C Looooops

http://poj.org/problem?id2115 參考人家的 如下 如i65534&#xff0c;當i3時&#xff0c;i1 其實就是 i(655343)%(2^16)1 有了這些思想&#xff0c;設對于某組數據要循環x次結束&#xff0c;那么本題就很容易得到方程&#xff1a; x[(B-A2^k)%2^k] /C 即 Cx(B-A)(mod 2^k) 此…

ASP.NET調用javascript腳本的常見方法小結

http://www.codesky.net/article/doc/201004/2010041706872.htm轉載于:https://www.cnblogs.com/ZC_Mo-Blog/archive/2010/11/23/1885125.html

python wait方法_Python條件類| 帶有示例的wait()方法

python wait方法Python Condition.wait()方法 (Python Condition.wait() Method) wait() is an inbuilt method of the Condition class of the threading module in Python. wait()是Python中線程模塊的Condition類的內置方法。 Condition class implements condition variab…

return編程python_python3 第二十一章 - 函數式編程之return函數和閉包

我們來實現一個可變參數的求和。通常情況下&#xff0c;求和的函數是這樣定義的&#xff1a;def calc_sum(*args):ax0for n inargs:ax ax nreturn ax但是&#xff0c;如果不需要立刻求和&#xff0c;而是在后面的代碼中&#xff0c;根據需要再計算怎么辦&#xff1f;可以不返回…

黑色背景下,計算照片白色的區域面積和周長

黑色背景下&#xff0c;計算照片白色的區域面積和周長 import cv2 img cv2.imread(E:\Python-workspace\OpenCV\OpenCV/beyond.png,1)#第一個參數為選擇照片的路徑&#xff0c;注意照片路徑最后一個為正斜杠其他都為反斜杠&#xff1b;第二個參數&#xff0c;其中1表示所選照…

php連接mssql數據庫的幾種方式

數據庫查詢不外乎4個步驟&#xff0c;1、建立連接。2、輸入查詢代碼。3、建立查詢并取出數據。4、關閉連接。 php連接mssql數據庫有幾個注意事項&#xff0c;尤其mssql的多個版本、32位、64位都有區別。 首先&#xff0c;php.ini文件中;extensionphp_pdo_mssql.dll ;extensionp…

通俗易懂:快速理解P2P技術中的NAT穿透原理

目錄1、基礎知識1.1、什么是NAT&#xff1f;1.2、為什么會有NAT&#xff1f;1.3、NAT有什么優缺點&#xff1f;2、NAT的實現方式2.1、靜態NAT2.2、NAPT3、NAT的主要類型3.1、完全錐型NAT&#xff08;Full Cone NAT&#xff0c;后面簡稱FC&#xff09;3.2、受限錐型NAT&#xff…

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

duration javaDuration Class toNanos()方法 (Duration Class toNanos() method) toNanos() method is available in java.time package. toNanos()方法在java.time包中可用。 toNanos() method is used to convert this Duration into the number of nanoseconds. toNanos()方…