So this should be really simple since I know it's possible (I just don't understand 'Set' very much).
So basically there is this TreeMap, let's call it aTree. So I need to do something like:
somethingHereProbably = aTree.keySet();
somethingHereProbably.toStringArray();
Create a Set object. Add elements to it. Create an empty array with size of the created Set. Convert the Set to an array using the toArray() method, bypassing the above-created array as an argument to it.
HashMap keySet() Method in Java keySet() method in Java is used to create a set out of the key elements contained in the hash map. It basically returns a set view of the keys or we can create a new set and store the key elements in them. Syntax: hash_map.keySet()
You can do
Map<String, Object> map = ...
String[] strings = map.keySet().toArray(new String[map.size()]);
This works for any kind of map, including TreeMap
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With