I am writing my first calculator. I want to break a string of numbers and signs into 2 collections.
I enter the following code:
protected static String Go (String s) { ArrayList <String> Numbers = new ArrayList <String> (); ArrayList <String> Simbols = new ArrayList <String> (); for (String c1 : s.split("[^0-9]+")) Numbers.add(c1); for (String c2 : s.split("[0-9]+")) Simbols.add(c2); When testing produces a variety of results, for example:
s="6-6"I get:Numbers=[6, 6] Simbols=[, -]s="+6+6"I get:Numbers=[, 6, 6] Simbols=[+, +]s="+6+6"I get:Numbers=[, 6, 6] Simbols=[+, +]
That is, for some reason, an empty element is placed at the beginning of the Simbols or Numbers collection. Because of this, I can not do anything further.