Q
qu0ll
I would like to code a method to convert a particular HashMap into a sorted
array. This is what I came up with:
public convert(final HashMap<String, Thing> things)
{
Thing[] tArray = new Thing[things.size()];
Collection<Thing> tCollection = things.values();
int i = 0;
for (Thing t : tCollection)
{
tArray[i++] = t;
}
Arrays.sort(tArray);
return tArray;
}
Well it works but is there a more efficient/elegant way of doing this?
Also, it would be nice to write it in such a way that it would convert any
HashMap not just those using Thing. Can anyone assist?
--
And loving it,
qu0ll
______________________________________________
(e-mail address removed)
(Replace the "SixFour" with numbers to email)
array. This is what I came up with:
public convert(final HashMap<String, Thing> things)
{
Thing[] tArray = new Thing[things.size()];
Collection<Thing> tCollection = things.values();
int i = 0;
for (Thing t : tCollection)
{
tArray[i++] = t;
}
Arrays.sort(tArray);
return tArray;
}
Well it works but is there a more efficient/elegant way of doing this?
Also, it would be nice to write it in such a way that it would convert any
HashMap not just those using Thing. Can anyone assist?
--
And loving it,
qu0ll
______________________________________________
(e-mail address removed)
(Replace the "SixFour" with numbers to email)