I had a HashSet and i stored the content of it in a String using .toString(). Is there any simple way to get the String back into a HashSet?
I saved some configurations for a program in a textfile, and now i’m trying to read the config.
I could probably do it by removing the first and the last characters [ ], and then just split it using split(). And then loop through and add it to a HashSet. But it feels like a big detour, there should be an opposite to .toString()?
So, is there any simpler way than the way i described?
The
toString()is not a conversion methods and classes usually don’t implement astatic fromStringmethod. So what you describe is the simplest way.Note that it will not reconstruct the Set correctly if the elements themselves contain
commacharacter.