• java中判断两个对象是否相等


    package ceshi.com.job;
    
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.List;
    
    public class EqualTest {
    
        /**
         * @param args
         */
        public static void main(String[] args) {
            // TODO Auto-generated method stub
            String A = "ABba";
            String B = "ABbaa";
            
            if (A.equals(B)) {
                System.out.println("相等");
                
            }else
                System.out.println("不相等");
            
            System.out.println("-------------");
    //        String C = new String("hello");
            String C = "hello";
            String D = "hello";
            
            if (C==D) {
                System.out.println("相等");
                
            }else
                System.out.println("不相等");
            System.out.println("——————————————————————");
            String[] E = {"1","2","3","4"};
            String[] F = {"1","2","3","4"};
            
            if (Arrays.equals(E,F)) {
                System.out.println("相等");
            }else
                System.out.println("不相等");
            System.out.println("---------ooo");
            String[] G = {"1","2","3","4"};
            String[] H = {"1","2","3","4"};
            if (G.length==H.length) {
                for (int i = 0; i < G.length; i++) {
                    if (G[i].equals(H[i])) {
    //                    System.out.println("相等");
                    }else
                        System.out.println("不相等");
                }
                System.out.println("相等");
            }else{
                System.out.println("长不不相等,不需要判断");
            }
            System.out.println("-------------");
            
            List<String> one = Arrays.asList("Tom","Anthony","Beijing");
            List<String> two = Arrays.asList("Tom","Anthony","Beijing");
            
            if (one.containsAll(two)) {
                System.out.println("相等");
            }else{
                System.out.println("不相等");
                
            }
            System.out.println("-----------");
            List<String> str1 = Arrays.asList("Tom","Anthony");
            List<String> str2 = Arrays.asList("Tom");
            
            if (str1.size() == str2.size()) {
                for (int i = 0; i < str1.size(); i++) {
                    if (str1.get(i).equals(str2.get(i))) {
                        //do thing
                    }else{
                        System.out.println("不相同");
                    }
                }
                System.out.println("");
                
            }else{
                System.out.println("长度不相等,没有必要比较");
            }
        }
            
        
    }
  • 相关阅读:
    基本处理函数(ProcessFunction)
    按键分区处理函数(KeyedProcessFunction)
    Flink 分流
    处理函数应用案例——TopN
    处理迟到数据
    hive 字段注释中文乱码
    Centos 关闭防火墙
    窗口处理函数
    hive posexplode 函数的使用举例
    框架——容器框架——spring_boot——actuator
  • 原文地址:https://www.cnblogs.com/51testing/p/7742664.html
Copyright © 2020-2023  润新知