To the top of the list

  • 2
  • Locked
Imagine people making appointments at a dental office where the waiting list acts like a stack rather than a queue: the last person to schedule is the first to have a drill taken to his or her tooth. We'll write a program that reflects this unusual situation: create a list and add 10 strings, but we'll add them to the beginning of the list rather than the end.
You can't complete this task, because you're not signed in.
Comments (16)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Usman Full Stack Developer at QA
5 July 2021, 12:27
im acc laughing (cryinng) at the fact that i spent so long on this 😂😂😂. i was complicating this so much haha. Hint - -dont over complicate it -look at the .add() method
Hoist
Level 8 , San Diego, United States
6 January, 19:31
https://codegym.cc/tasks/com.codegym.task.task07.task0710
Khongpak Phupkdee
Level 15 , Chiangrai, Thailand
16 April 2021, 02:02
The program should add lines to the beginning of the list. What does "add lines" mean?
ImDevin
Level 15 , Old Town, United States
19 April 2021, 04:08
it just means to add the new string to the beginning of the list
Yamini Krishna
Level 33 , Piscataway, United States
25 March 2021, 01:06
Can I know what is wrong in my code, that the test is failing ArrayList<String> strings = new ArrayList<String>(); BufferedReader r = new BufferedReader(new InputStreamReader(System.in)); for(int i=0; i<10;i++){ strings.add(i,r.readLine()); System.out.println(strings.get(i)); }
Roman
Level 41
26 March 2021, 06:59
Please post your question with the attached solution in the section Help.
Samuel
Level 16 , London, United Kingdom
3 April 2021, 18:02
Hi Yamini, I am sure that you have already solved this task, but to make it easier you should have a loop to add the strings from the keyboard and a loop to print the strings. You can take out System.out.println(strings.get(i)) from the for loop and put it in a FOR EACH LOOP.
Hoist
Level 8 , San Diego, United States
6 January, 19:32
https://codegym.cc/tasks/com.codegym.task.task07.task0710
David Haines
Level 13 , La Crosse, United States
14 July 2020, 03:08
I'm beginning to get a bit irritated with java. in general. I had originally coded this (and verification failed miserably): list.add (0, s); After 30-40 minutes of trying to determine why, I somehow managed to remove the space between list.add and (0,s) without realizing it, and tried one more time and everything was fine. Can someone explain to me why no space in between works but having a single space in between doesn't?
Roman
Level 41
14 July 2020, 06:40
Has the test failed with a space or the code did not work? Send this code in PM
Devonte A
Level 18 , Rubery, United Kingdom
28 May 2020, 14:54
Consider that when you add an element to a position/index in an array it will shift the elements 1 to the right e.g. adding to index 1 will push the element at index 1 to index 2 and the new inserted element will be at index 1. :)
rishabh
Level 8 , Mumbai, India
13 November 2019, 07:21
whats wrong in my code.. 2nd and 3rd requirement are not fulfilled.
Roman
Level 41
14 November 2019, 06:41
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
Bhavishya Samriya
Level 8 , Jaipur, India
11 July 2019, 07:01
what is wrong with my code
Roman
Level 41
12 July 2019, 06:43
If you need help, something isn't right in your code, the server won't accept your solution (even if you are 100% sure that it is correct). Describe your question/issue in the HELP section at codegym.cc/help.
Bhavishya Samriya
Level 8 , Jaipur, India
13 July 2019, 04:50
Thank you But I figured it out. There was a mistake in the placement of zero in list.add();