Skip to content Skip to sidebar Skip to footer

Longlongvalue From Objective C In Java?

How to convert this Objective C code in Java ? NSMutableString * thisPart = [[NSMutableString alloc] init]; UInt64 intVal = (UInt64)[thisPart longLongValue]; if (!intVal) { isBad =

Solution 1:

I'm going to assume that you don't care about the NSMutableString bit which would probably similar to the StringBuilder/StringBuffer classes. A UInt64 would appear to be a 64bit unsigned int? Then you could use the String constructor provided by BigInteger(String)

StringBuilderthisPart=newStringBuilder("12345678901234567890");
try {
    BigIntegerintVal=newBigInteger(thisPart.toString());
} catch (NumberFormatException e) {
    System.out.println("Bad value");
    isBad = true;
    break; // or return or what have you
}

Solution 2:

Stringstr = "1234567890";
long l = Long.parseLong(str);

You'll need error handling around the parse call.

Post a Comment for "Longlongvalue From Objective C In Java?"