String turn long, Long.valueOf () and Long.parseLong () difference and Long.longValue ()

1, java how the string is converted into Long (); (conventional method 2)

method 1:

long l = Long.valueOf("String");

Method 2:

long l = Long.parseLong(“String”); 
 
 或    long l = Long.parseLong(“String”, int radix); 

2, Long.ValueOf ( "String") and Long.parseLong ( "String") difference

Long.ValueOf ( "String") returns the Long type packaging

Long.parseLong ( "String") returns a long basic data types

Source as follows:

    public static Long valueOf(String s) throws NumberFormatException
    {
        return Long.valueOf(parseLong(s, 10));
    }
   public static long parseLong(String s) throws NumberFormatException {
       return parseLong(s, 10);
   }

3. Comparison by address and by value

tbItem.getId () returns a Long object, is a Long itemId (i.e. an object),

If the direct comparison, the address corresponding to the comparison, tbItem.getId () == itemId comparing the address , tbItem.getId () longValue () == itemId;. Is compared values .

tbItem.getId()==itemId;

If you want to compare the value needed longValue in () takes a value

tbItem.getId().longValue()==itemId;
Published 15 original articles · won praise 0 · Views 503

Guess you like

Origin blog.csdn.net/qq_36335126/article/details/103809970