Skip to main content
2 of 2
Add example.
Comintern
  • 4.2k
  • 1
  • 17
  • 26

Assuming that the characters on the left of the ">" are unique (or the doubles to the right are unique), the easiest way I can think of to do this is to use a HashMap object. Just split the string on the ">", and use one of them as the key and one as the value. When you're done, just retrieve the 2 collections with the keySet() and values() methods and then convert them with toArray().

I'd also take a look at the string split() method - makes parsing really easy with a fixed format like this.

Edit:

    HashMap<String, Double> lists = new HashMap<String, Double>();
    while (scanner.hasNext()) 
    {
        String[] temp = scanner.next().split(">");
        lists.put(temp[0], Double.parseDouble(temp[1]));
    }
Comintern
  • 4.2k
  • 1
  • 17
  • 26