Comparison of Java int types

Recently, I encountered a problem in the project about the comparison of the size of the int attribute in the two objects.

 

 

1: When you want to compare the size of int properties in two objects, there are two workarounds

 The first: reassignment

               User newUser = userService.getByNameAndCompanyId(userName,companyId);
               User oldUser = userService.getById(userId);

                int newId = newUser.getId ();

                int oldId = oldUser.getId();

               At this point, the newId and oldId can be compared.

The second: convert the int type in the object to the String type, and then compare.

             String.valueOf(newUser.getId())

 

 

Note: You cannot directly use == to compare basic type data (object properties), and use == to compare addresses.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326931139&siteId=291194637