Shuffled just in time

  • 10
  • Locked
Games with lists are the best! Does that sound like an advertisement? Perhaps the best advertisement for a programming language is its frequent use. Let's advertise lists as we complete this task: enter numbers m and n, enter n strings and put them in a list. Then perform a simple manipulation: move the first m strings to the end of the list
You can't complete this task, because you're not signed in.
Comments (20)
  • Popular
  • New
  • Old
You must be signed in to leave a comment
Aron
Level 18
12 July 2021, 20:26
Hint - list.remove(0) removes an element from a list and also returns it, so you can wrap the return in a list.add statement. which adds it to the end of the list i.e list.add(list.remove(0))
ImDevin
Level 15 , Old Town, United States
23 April 2021, 20:38
Spent way too much time doing this task, but while trying to figure it out, did learn a lot, so it wasn't all a waste. Tried using some methods as suggested by others, but found it wasn't necessary, in fact, it didn't work (like .sublist() & .addAll()), as you need to create more than one list, which is against the Condition of the task. in the end, simple methods(.get(), .add(), .remove()) was all it was needed. Again, it's best not to over-think it and not make it more complicated than necessary. Happy coding! :)
ImDevin
Level 15 , Old Town, United States
23 April 2021, 02:36
It took too long to figure out what they were asking for. Previous comments were very helpful. Thanx all.
Lin Chen
Level 14 , Richardson, United States
21 February 2021, 18:02
I am a little bit confused for the removal function. But it seems that it is looping the i but not the list itself so it doesn't need to use Iterator.
Mihai Bone
Level 8 , Bucharest, Romania
8 December 2020, 02:02
Tips : Replace the input words with something similar, It will help you when you play with the list. test0 test1 test2 test3
Dyrits
Level 22
15 July 2020, 10:47
You can use the...
.addAll()
...method with the...
.subList()
...method, and the...
.clear()
...method as well.
ziv fisher
Level 9 , Petah Tikva, israel
3 October 2020, 11:29
...method with the...
list.subList()
// To copy the first M Strings to the end of the ArrayList.
list.remove()
// To remove the first M Strings in the ArrayList(inside a loop of course).
andy 6473
Level 9 , Bangalore, India
14 July 2020, 16:39
display the list each value on a new line , what is it roman
Roman
Level 41
17 July 2020, 06:07
For example, the list {"one", "two", "three"} should be displayed as one two three
Seferi
Level 22 , United Federation of Planets
30 June 2020, 18:50
I did this with for loops and removed the "M" items with for loop. Why don't I get a ConcurrentModificationException with it ?
Lucas Hoage
Level 14 , Savannah, United States
31 May 2020, 04:41
Now that was fun. Probably the best exercise I've done so far.
Artur Verdyan
Level 24 , Hoboken, United States
4 March 2020, 17:39
I think I read this task for 20 times but still no idea what should I do :)
30 March 2020, 23:59
In case you solve it, is help for other people. First number from input 8(you add 8 Strings to the list) Second number from input 4(you move first 4 elements from the list to the end of the list) Short: you add 8, you copy 4 to the end of the list, you remove the first 4 from the list.