It does duplicate but it is failing.
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 {
// write your code here
// Read strings from the console and declare an ArrayList here
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
ArrayList<String> totatlList = new ArrayList<String>();
for (int i = 0; i < 10; i++)
{
String s = reader.readLine();
totatlList.add(s);
}
ArrayList<String> result = doubleValues(totatlList);
// Display result
for (String s : result)
{
System.out.println(s);
}
}
public static ArrayList<String> doubleValues(ArrayList<String> list)
{
//write your code here
ArrayList<String> totatlList = new ArrayList<String>();
for (String s : list)
{
if (s.equals("alpha") || s.equals("beta") || s.equals("gamma"))
{
totatlList.add(s);
totatlList.add(s);
}
else
{
totatlList.add(s);
}
}
return totatlList;
}
}