I have written this:
public static void main(String[] args) {
LinkedList<String> list = new LinkedList<>();//declare your list
Scanner input = new Scanner(System.in);//create a scanner
System.out.println("How many participants? ");
int nbr = input.nextInt();//read the number of element
input.nextLine();
do {
System.out.println("What is the name of the people?");
list.add(input.nextLine());//read and insert into your list in one shot
nbr--;//decrement the index
} while (nbr > 0);//repeat until the index will be 0
System.out.println(list);//print your list
The output is:
Jack, Frank
What I want to do is changing the content of the linked list. For example I wrote 2 names Jack and Frank. Then I want to add Jack's surname so that linked list will be:
Jack Adam, Frank
What should I do?