Home > other >  Replace = with equals in java
Replace = with equals in java

Time:11-24

I am new to Java. I want to replace = with equals for Integer object

      public boolean isResult(Integer a, Integer b, Integer c, Integer d){
        return a   b!= c   d

I tried

 Integer res1 = a   b
 Integer res 2 = c   d

if(!res1.equals(res2)){
    return;
 }

Is there a way to minimize the code rather than again assigning to an object.

CodePudding user response:

public static boolean isResult(Integer a, Integer b, Integer c, Integer d) {
    
    if (!Optional.of(a b).equals(Optional.of(c d))){
        return false;
    }
    return true;
}

You can use Optional İf you don't want to use res1 and res2

  •  Tags:  
  • java
  • Related