timezone - Java: getTimeZone without returning a default value -
i have following instruction:
timezone zone = timezone.gettimezone("asia/toyo");
obviously, should return null, return default timezone, not desired behaviour case. java doc:
returns specified
timezone
, or gmt zone if given id cannot understood.
is there way corresponding timezone , null value if string not indicate valid timezone?
i don't find solution timezones , iterate on them.
instead of iterating use:
boolean exists = arrays.aslist(timezone.getavailableids()).contains("asia/toyo");
or:
boolean exists = arrays.stream(timezone.getavailableids()).anymatch("asia/toyo"::equals);
if need often, putting available ids in hashset more efficient.
Comments
Post a Comment