The exercises in lesson 6 from level 7 are too hard for me. I need more explanation before I am able to do these. Can someone refer me to an article or another tutorial that will explain the use of ArrayLists in more detail as I'm already struggling with these for more than 1 day. I am on a very tight schedule to finish this course. Any help is appreciated!!!
package com.codegym.task.task07.task0717;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
/*
Duplicating words
*/
public class Solution {
public static void main(String[] args) throws Exception {
// Read strings from the console and declare an ArrayList here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> original = new ArrayList<>();
for (int i = 0; i < 10; i++)// read 10 words from keyboard and add them to the Arraylist original
{
String s = reader.readLine();
original.add(s);
}
// Display result
for(int i = 0; i < original.size(); i++)
{// why does the following code not work?? for(String s : result)
System.out.println(original.get(i));//prints the original ArrayList
}
ArrayList<String> result = doubleValues(list);
for (String s : result){
System.out.println(s);
}
}
public static ArrayList<String> doubleValues(ArrayList<String> list) {
//write your code here
for(int i = 0; i < original.size(); i++)// loop over the original ArrayList and double the individual items
{
original.add(i+1, original.get(i));
i++;
}
return result;
}
}