CodeGym /Java Course /New Java Syntax /Practice with lists

Practice with lists

New Java Syntax
Level 13 , Lesson 5
Available

"Finally, you're done. I'm tired of trying to keep your tasks in my head. Here's a couple more to keep you in shape:"

13
Task
New Java Syntax, level 13, lesson 5
Locked
Words in reverse
Read 5 words from the keyboard and add them to a list of strings. Remove the 3rd item in the list, and then display the remaining items in reverse order.
13
Task
New Java Syntax, level 13, lesson 5
Locked
Three arrays
1. Enter 20 numbers from the keyboard, save them in the numbers list, and then sort them to three other lists: - Numbers divisible by 3 (x%3==0) end up in the divBy3 list, - Numbers divisible by 2 (x%2==0) end up in the divBy2 list, - and all the rest remain in the others list, - Numbers divisible b
13
Task
New Java Syntax, level 13, lesson 5
Locked
R or L
1. Create a list of words and populate it yourself. 2. The fix method should: 2.1. remove all words containing the letter "r" from the list 2.2. duplicate all words containing the letter "l". 2.3. if a word contains both "r" and "l", then leave it unchanged. 2.4. don't do anything to other words. Fo
13
Task
New Java Syntax, level 13, lesson 5
Locked
More Sam-I-Am
1. Create a string list consisting of the words: "Sam", "I", "Am". 2. After each word, insert the word "Ham" into the list. 3. Display the result on the screen, each list element on a new line.
13
Task
New Java Syntax, level 13, lesson 5
Locked
Duplicating words
1. Read 10 words from the keyboard and add them to a list of strings. 2. The doubleValues method should duplicate words like this: alpha, beta, gamma, -> alpha, alpha, beta, beta, gamma, gamma. 3. Display the result, each value on a new line.
13
Task
New Java Syntax, level 13, lesson 5
Locked
Checking the order
1. Read 10 words from the keyboard and add them to a list of strings. 2. Determine whether the list is ordered by increasing string length. 3. If it is not, then display the index of the first element that violates this order.
Comments (75)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Mindaugas Level 23, Lithuania
5 September 2023
in first task - Words in reverse, if you create second ArrayList for solution, it will not pass testing, although everything is working, so think of more simple solution :)
Rebecca Zee Level 10, New York, United States
18 July 2023
The More Sam-I-Am task shouldn't even be considered medium. I would consider it an easy task. I didn't even have to use any looping to add any elements into the ArrayList. If you paid attention to the lesson right before this, it shouldn't even be hard to do.
Anonymous #10782038 Level 24, United States of America
18 March 2024
its not medium, its listed as an easy..
Xavi Martin Level 22 Expert
25 October 2022
Can someone explain to me what this symbol means? ->
Dzmitry Antsipin Level 29, Berlin, Germany
22 December 2022
It's about lambda expressions - we'll meet with it afterwards
Michael Amann Level 22, United States of America, United States
21 April 2022
I think showing the students how to read from a file earlier would help immensely in testing. Instead of typing over and over you could just read from a file to test input and NOT have to take that code out and implement another input method to submit.
ayadi1 Level 18, berkane, Morocco
30 April 2022
i think so 😬
AHMET YORULMAZ Level 8, Germany, Germany
27 October 2021
"If half or more of your actions seem to be meaningless, don't worry: you probably clearly understand the fragility of existence"👍
Justin Smith Level 41, Greenfield, USA, United States
11 July 2021
A hint that makes quite a few of these much easier... a for loop is not required to start counting from small to large. You can go the other way (i.e. for(int i = 9; i >= 0; i--) instead of for(int i = 0; i < 10; i++). This is really useful when removing elements from an arraylist or adding them into a specific location, where you don't want to affect the index values of the elements you have yet to iterate through.
Romant Level 15, Russia, Russian Federation
22 April 2022
Thankyou! Idea of backward looping helps to avoid exception on members numbering when adding new members.
DarthGizka Level 24, Wittenberg, Germany
29 May 2021
task0715 (More Sam-I-Am) caveat: you will get failed if you initialise the ArrayList and fill it in one go. They want you to add the initial three strings in a separate statement to an initially empty list (but Collections.addAll() gets accepted for that, for example).
Gokhan35 Level 37, Izmir, Turkey
5 January 2022
ArrayList<String> list = new ArrayList<String>(Arrays.asList("Sam", "I", "Am")); I did it like this but you have to import the Arrays class using; import java.util.Arrays;
Libby Level 20, United Kingdom
17 January 2021
Is there any way to see output and input on IntelliJ?
Olha Level 40, Fremont Expert
18 January 2021
Please contact the support team at support@codegym.cc for further assistance.
Ajani Level 16, Jacksonville, United States
9 January 2021
So i notice this a lot recently when i compare how I solve a problem to how site's coders solved it. When forming an array or list, and taking entries from a keyboard the site's programmers almost always write the entry to a variable before then taking that variable and adding it to a list. Why take the extra step? why not just code the typed entry directly into your list/array?
DarthGizka Level 24, Wittenberg, Germany
29 May 2021
Catching a value in an explicit variable has several advantages: * you can give the value a name that tells you what it means (can be important with complicated math) * it allows you to watch the value in a debugger * it helps with breaking complex tasks/expressions into simpler, more elementary ones that are easier to process for humans; this means fewer coding errors when writing code and less overload when reading it
Donny Level 15, San Francisco, United States
3 January 2021
My code passed the tests on Javarella, but I don't understand why this code worked: int a = Integer.parseInt(bis.readLine()) In using the Integer.parseInt method, don't we convert a string into an int, that is a primitive value? How can that int then be added to an ArrayList when ArrayLists cannot take primitive values. Don't we have somehow use the Integer wrapper class to turn the int into an object? Thanks for any thoughts on this. Happy New Year 2021 to all! Donny
Mina Nabil Level 17, Sydney, Australia
4 January 2021
What actually happens when we add a primitive type value to an ArrayList is that an object of the associated wrapper class - with the primitive value “wrapped inside” - is automatically created and added to the list.This is known as autoboxing.