I have a string that comes out like this:
String line = "2022{yyyy}{mm}{dd}";
I want to split it into an arraylist like this:
2022
yyyy
mm
dd
how can i do this?
I have a string that comes out like this:
String line = "2022{yyyy}{mm}{dd}";
I want to split it into an arraylist like this:
2022
yyyy
mm
dd
how can i do this?
One approach:
String line = "2022{yyyy}{mm}{dd}";
String[] parts = line.split("[{}]+");
System.out.println(Arrays.toString(parts)); // [2022, yyyy, mm, dd]
Another possibility might be to do a regex find all on \w+
using a formal pattern matcher.
Here would be an example approach if you wanted to use four capturing groups:
Having said that, Tim's approach is much simpler and I'd go for that.