久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

比較兩個字節數組?(爪哇)

Compare two Byte Arrays? (Java)(比較兩個字節數組?(爪哇))
本文介紹了比較兩個字節數組?(爪哇)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個字節數組,里面有一個~已知的二進制序列.我需要確認二進制序列是它應該是什么.除了 == 之外,我還嘗試了 .equals,但都沒有成功.

I have a byte array with a ~known binary sequence in it. I need to confirm that the binary sequence is what it's supposed to be. I have tried .equals in addition to ==, but neither worked.

byte[] array = new BigInteger("1111000011110001", 2).toByteArray();
if (new BigInteger("1111000011110001", 2).toByteArray() == array){
    System.out.println("the same");
} else {
    System.out.println("different'");
}

推薦答案

在你的例子中,你有:

if (new BigInteger("1111000011110001", 2).toByteArray() == array)

在處理對象時,java中的==會比較引用值.您正在檢查 toByteArray() 返回的對數組的引用是否與 array 中保存的引用相同,這當然不可能是真的.此外,數組類不會覆蓋 .equals() 因此其行為是 Object.equals() 的行為,它也只比較參考值.

When dealing with objects, == in java compares reference values. You're checking to see if the reference to the array returned by toByteArray() is the same as the reference held in array, which of course can never be true. In addition, array classes don't override .equals() so the behavior is that of Object.equals() which also only compares the reference values.

為了比較兩個數組的內容,數組類

byte[] array = new BigInteger("1111000011110001", 2).toByteArray();
byte[] secondArray = new BigInteger("1111000011110001", 2).toByteArray();
if (Arrays.equals(array, secondArray))
{
    System.out.println("Yup, they're the same!");
}

這篇關于比較兩個字節數組?(爪哇)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to wrap text around components in a JTextPane?(如何在 JTextPane 中的組件周圍環繞文本?)
MyBatis, how to get the auto generated key of an insert? [MySql](MyBatis,如何獲取插入的自動生成密鑰?[MySql])
Inserting to Oracle Nested Table in Java(在 Java 中插入 Oracle 嵌套表)
Java: How to insert CLOB into oracle database(Java:如何將 CLOB 插入 oracle 數據庫)
Why does Spring-data-jdbc not save my Car object?(為什么 Spring-data-jdbc 不保存我的 Car 對象?)
Use threading to process file chunk by chunk(使用線程逐塊處理文件)
主站蜘蛛池模板: 欧美一级片在线观看 | 91在线视频播放 | 三级黄色片在线 | 日韩欧美操 | 精品1区2区 | 久久久精品| 久久69精品久久久久久久电影好 | 欧美日韩精品一区二区三区蜜桃 | 一二区视频 | 欧美一区二区在线播放 | 久久久国产精品一区 | 色欧美综合 | 99影视| 不卡一二区 | 久久精品国产精品青草 | 国产精品小视频在线观看 | 日韩一区二区三区在线视频 | 久久国产婷婷国产香蕉 | 日韩精品在线观看视频 | 免费成人高清在线视频 | 亚洲国产精品久久久久秋霞不卡 | 亚洲欧美一区二区三区国产精品 | 久草精品在线 | 97伦理最新伦理 | 久久久免费电影 | 欧美日韩在线观看视频网站 | 精品国产1区2区3区 一区二区手机在线 | 蜜桃视频在线观看www社区 | 国产一区二区毛片 | 992人人草| 欧美精品综合在线 | 天天在线操 | 久久久久国产精品一区二区 | a级片在线观看 | 精品久久国产老人久久综合 | 日韩一区二区在线视频 | 无毛av| 欧美成人自拍视频 | 日韩欧美精品在线播放 | 91成人在线 | 看片91 |