문제

I have a variable of type "long"

 long time = System.currntTimeMillis();

I would like to pass it to a method that requires a string. If this wasn't a primative type I would call time.toString(): but that is not a valid method.

What I am doing is

 method("" + time);

And this creates a string, but is there a better way or more optimal way to do this?

도움이 되었습니까?

해결책

You can use:

Long.toString(time) or String.valueOf(time).

Take a look at this answer

다른 팁

Perhaps

method(Long.toString(time));
 method("" + time);

is inefficient. String API exposes lots of static utility overloaded methods for different types:

String.valueOf(time)

Or

method(String.valueof(time));
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top