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
Shuffled just in time
- 10
Locked
Comments (20)
- Popular
- New
- Old
You must be signed in to leave a comment
Aron
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))
+2
ImDevin
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! :)
+2
ImDevin
23 April 2021, 02:36
It took too long to figure out what they were asking for. Previous comments were very helpful. Thanx all.
0
Lin Chen
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.
0
Mihai Bone
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
0
Dyrits
15 July 2020, 10:47
You can use the...
...method with the... ...method, and the... ...method as well. +2
ziv fisher
3 October 2020, 11:29
...method with the...
// To copy the first M Strings to the end of the ArrayList.
// To remove the first M Strings in the ArrayList(inside a loop of course). 0
andy 6473
14 July 2020, 16:39
display the list each value on a new line , what is it roman
0
Roman
17 July 2020, 06:07
For example, the list {"one", "two", "three"} should be displayed as
one
two
three
0
Seferi
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 ?
0
Lucas Hoage
31 May 2020, 04:41
Now that was fun. Probably the best exercise I've done so far.
0
Artur Verdyan
4 March 2020, 17:39
I think I read this task for 20 times but still no idea what should I do :)
+4
hidden #10568956
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.
+1