Use the keyset () method and change the set to string array? Java

So it should be very simple because I know it's possible (I just don't know 'set')

So basically there is this treemap, which we call atree So I need to do something:

somethingHereProbably = aTree.keySet();
somethingHereProbably.toStringArray();

Solution

You can do it

Map<String,Object> map = ...
String[] strings = map.keySet().toArray(new String[map.size()]);

This applies to any type of map, including treemap

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>