undefined

Practice with ArrayList

Java Syntax
Level 7 , Lesson 6
Available

"You're just sitting idle again? You're a robot! Robots do something all the time. Here are a couple of exercises to keep you from rusting. But first, a few hints:"

"Hint 1:

By 'list', we usually mean an ArrayList."

"Hint 2:

A 'string' means a String object."

"Hint 3:

'Create a list of strings' most often means the following: ArrayList<String> list = new ArrayList<String>();"

undefined
2
Task
Java Syntax, level 7, lesson 6
Locked
What sort of list is that?
Java programmers love their lists just as much as conscientious homemakers love their shopping lists and to-do lists. If you haven't fallen in love with them yet, it's time to start. And a programmer's love begins with code. So, in this task, we'll create a list of strings, add 5 different strings, and then display the size of the list on the screen. Then we'll display the contents of the list. Easy peasy!
undefined
10
Task
Java Syntax, level 7, lesson 6
Locked
Longest string
Let's measure strings! And we'll complete a programming task at the same time: create a string list, read 5 strings from the keyboard, and add them to the list. Then use a loop to find the longest string (or longest strings, if there is more than one). A country should know its heroes: the longest strings will be displayed.
undefined
5
Task
Java Syntax, level 7, lesson 6
Locked
Expressing ourselves more concisely
Brevity is the soul of wit. In the this task, let's celebrate brevity by doing the following: create a list, read 5 strings from the keyboard, add them to the list, find the shortest string, and then display it. If several strings are shortest, we'll display them all, each on a new line. Any questions, private?!
undefined
2
Task
Java Syntax, level 7, lesson 6
Locked
To the top of the list
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.
undefined
5
Task
Java Syntax, level 7, lesson 6
Locked
Remove and insert
Manipulating lists in Java is almost as easy and enjoyable as manipulating people! Anyway, about those lists. Here's what you need to do: create a list and add 5 strings. Then remove the last string and insert it at the beginning. Repeat this manipulation 13 times and then display the contents of the list. Why? Don't ask, just believe: it's necessary.
undefined
10
Task
Java Syntax, level 7, lesson 6
Locked
Shortest or longest
Java games with lists are very popular. This makes sense, since they are all so simple and interesting. Join in the fun! In this task, we create a list of strings. Then we add 10 strings from the keyboard. The most interesting part is that we'll determine whether the shortest string or the longest string is encountered first in the list. If more than one string is shortest or longest, we'll consider the very first one we encounter.
Comments (64)
TO VIEW ALL COMMENTS OR TO MAKE A COMMENT,
GO TO FULL VERSION
Maksim Lukjanskis Level  17, Riga, Latvia
30 November 2020
(String str : list), someone can explain me what does " : " mean?
Neil Hainer Level  19, Mount Laurel, United States
19 November 2020
Expressing ourselves more concisely: What's wrong with this statement? The verifery tells me: List<String> myStrings = new ArrayList<String>(); "Declare a string list variable and immediately initialize it." Failed. I don't see the problem. The code runs correctly.
Mihai Bone Level  8, Bucharest, Romania
20 October 2020
I did melt my brain with those ones but I start to like them. Once you understand it(ArrayList) then the only limit is your imagination. In one exercise I did use 3 loops and I was kind of disappointed. In the last one I was able with just 2 loops and it did feel good to see the improvement.
Ian De Bie Level  26, Los Angeles, United States
27 June 2020
i feel dirty declaring arraylist reference variables instead of the list interface. i wish they would allow both so i don't fall into bad habits...
illia Level  8, Portland, United States
17 June 2020
nice stuff system.out.println("java is the best")
bob Level  8, Milan, Italy
7 June 2020
good stuff. i love this course. can't wait to finish this, i smell "java core"
Łukasz Level  18, GDANSK, POLAND
29 May 2020
Java Syntax Level 7, Lesson 6 Very imprecise task exercise. "If several strings qualify as the longest, you must display each one in a new row." I made a range of +/- 2 letters and had errors. Tips, Only when I set only the longest word test passed without bugs. More precision in formulating CG tasks!
Brandon Level  9, Toledo, United States
18 May 2020
Arrays and Array lists seem way easier than some earlier topics. Array lists seem especially user friendly, and will likely be very useful.
Ted404 Level  11, Dubai, United Arab Emirates
13 March 2020
lernt smth today
Michael Brimage Level  19, Washington D.C., United States
4 March 2020
How much should we rely on Stackoverflow and google? I feel like, in level 7, I am relying on outside resources too much to complete these exercises. Are there others in a similar situation? is this normal?