Problem: I have a String 100, 200, boxes
. I want to convert this String into an object, let's say TreeMap<String, List>
, with 100, 200
as a List of values and boxes
as a String that is a key.
The result should look like [100, 200]: "boxes"
.
Later I would like to access the values: my_map.get("boxes")[0]
or my_map.get("boxes")[1]
for example.
My Solution: Let's say I have a file with 3 columns, I read the data, split it and iterate over each line splitting the line on the go. I assume I have [100, 200, "boxes"]
. Now in python I could simply access the elements I need by providing a range of indexes like [0:1]
.
How to do the same thing in Java?
for (String line : mydata.split("\n|\r\n")) {
String[] sl = line.split(" |\t");
String[] my_two_elements = sl[0:1]; <-- No way!
}