java Long datatype comparison

前端 未结 4 664
别那么骄傲
别那么骄傲 2020-12-15 03:41

Why does the code below return false for long3 == long2 comparison even though it\'s literal.

public class Strings {

    p         


        
4条回答
  •  误落风尘
    2020-12-15 04:11

    If you want to do

          str3==str2
    

    do like this..

         str3.longValue()==str2.longValue()
    

    This serves your purpose and much faster because you are comparing two primitive type values not objects.

提交回复
热议问题