0

I am trying to obtain an array of Strings (dummy) which is to be converted to a custom object Combo, by splitting every String contained in a second array (readarray). This second array is obtained by splitting the contents of a file. Even though the array obtained by splitting the file's contents seems to be working fine, I can't seem to successfully split the Strings it contains, I get one empty return (dummy[0]) and the ones after are null. Also, readFromFile() simply uses a FileInputStream to return the full String the file contains.

ArrayList<Combo> combos=new ArrayList<>();
String[] dummy;
String read=readFromFile();
String[] readarray=read.split("#");
for (String ss:readarray) {
    dummy=ss.split("-");
    Combo combo=new Combo(dummy[0],Integer.parseInt(dummy[1]),Integer.parseInt(dummy[2]),Integer.parseInt(dummy[3]));
    combos.add(combo);
}

This is the String the file contains from which the above reads:

#22/09/2020-0900-2300-30#22/09/2020-0930-2330-30#22/09/2020-0900-2300-15

Help would be very much appreciated, thanks a lot.

1 Answer 1

1

remove the # from the beginning or the end of your string and you are fine. because it will create the first empty object in your array.

Sign up to request clarification or add additional context in comments.

1 Comment

Looks like i shouldn't write a comment saying "thanks", but, thanks. I spent so much time on this while knowing it had to be something simple, thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.