Java 实例 - 判断数组是否相等

Java 教程 · 2019-02-10 13:29:01

以下实例演示了如何使用 equals ()方法来判断数组是否相等:

Main.java 文件

import java.util.Arrays; public class Main { public static void main(String[] args) throws Exception { int[] ary = {1,2,3,4,5,6}; int[] ary1 = {1,2,3,4,5,6}; int[] ary2 = {1,2,3,4}; System.out.println("数组 ary 是否与数组 ary1相等? :" +Arrays.equals(ary, ary1)); System.out.println("数组 ary 是否与数组 ary2相等? :" +Arrays.equals(ary, ary2)); } }

以上代码运行输出结果为:

数组 ary 是否与数组 ary1相等? :true
数组 ary 是否与数组 ary2相等? :false

点击查看所有 Java 教程 文章: https://www.codercto.com/courses/l/12.html

查看所有标签

Pragmatic Thinking and Learning

Pragmatic Thinking and Learning

Andy Hunt / The Pragmatic Bookshelf / 2008 / USD 34.95

In this title: together we'll journey together through bits of cognitive and neuroscience, learning and behavioral theory; you'll discover some surprising aspects of how our brains work; and, see how ......一起来看看 《Pragmatic Thinking and Learning》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Base64 编码/解码
Base64 编码/解码

Base64 编码/解码

URL 编码/解码
URL 编码/解码

URL 编码/解码