Answers for "how to compare long with int java"

1

long vs int java

An int is a 32-bit integer; a long is a 64-bit integer. Which one to use depends on how large the numbers are that you expect to work with.

int and long are primitive types, while Integer and Long are objects. 
  
  Primitive types are more efficient, but sometimes you need to use objects;
for example, Java's collection classes can only work with objects, 
so if you need a list of integers you have to make it a List<Integer>, for example (you can't use int in a List directly).
Posted by: Guest on August-15-2021
2

java integer compareto

public class IntegerCompareToExample {  
    public static void main(String[] args) {      
        // compares two Integer values numerically  
          Integer x = new Integer("90");  
          Integer y= new Integer("58");  
          int retResult =  x.compareTo(y);        
          if(retResult > 0) {  
             System.out.println("x is greater than y");  
          } else if(retResult< 0) {  
             System.out.println("x is less than y");  
          } else {  
             System.out.println("x is equal to y");  
          }  
    }  
}
Posted by: Guest on April-26-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language