Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void addRecipes() {
- int index = 0;
- String name = "";
- int duration = 0;
- ArrayList<String> ingredients = new ArrayList<>(); //create new list
- for (int i = 0; i < data.size(); i++) {
- if (index == 0) {
- name = data.get(i);
- }
- if (index == 1) {
- duration = Integer.valueOf(data.get(i));
- }
- if (index > 1 && !data.get(i).equals("")) { //this adds stuff to arraylist until empty line hit
- ingredients.add(data.get(i));
- }
- if (data.get(i).equals("") || i == (data.size() - 1)) {
- ArrayList<String> tempList = new ArrayList<>(); //creates new arraylist
- for (String items : ingredients) {
- tempList.add(items); //fills it with values from the main arraylist
- }
- Recipe recipe = new Recipe(name, duration, tempList); //why does this work when the temp "resets" every loop?
- recipeList.addRecipe(recipe);
- ingredients.clear();
- index = 0;
- continue;
- }
- index++;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement