This week's book giveaway is in the Beginning Java forum.
We're giving away four copies of Get Programming with Java (MEAP only) and have Peggy Fisher on-line!
See this thread for details.
Win a copy of Get Programming with Java (MEAP only) this week in the Beginning Java forum!

Etibar Hasanov

Greenhorn
+ Follow
since Jan 03, 2017
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Etibar Hasanov

When key has null value in map the result of merge should be removing key from the map


When I print this I get {Jenny=Skyride}. But by the book it should be removing key from map. Did I understand wrong or what?
In page 25, For the properties of member inner class is written that it can't declare static fields or methods

When I declared static final variable the code didn't complain. Am I doing something wrong?
In the answer of review tests 18 it is written that

A, B, C, E. Checked exceptions are required to be handled or declared. Runtime
exceptions are allowed to be handled or declared. Errors are allowed to be handled or
declared, but this is bad practice.


Seems like there is typo. It seems that it should have been just B,C,E

Liutauras Vilda wrote:

Etibar Hasanov wrote:But I wonder when it tries to set "Sue"

At this point List is size zero probably. Try to use add() instead set().



add doesn't work, and in my opinion it shouldn't work as well. Because the list size gets fixed  if it is converted from Array into List
I just ran the following code from the example

But I wonder when it tries to set "Sue", it gives ArrayIndexOutOfBoundsException exception
The answer on page 342 says that

24. C. Converting from an array to an ArrayList uses Arrays.asList(names). There is
no asList() method on an array instance. If this code were corrected to compile, the
answer would be option A.



the question is as followingA. Sue
B. Tom
C. Compiler error on line 7.
D. Compiler error on line 8.
E. An exception is thrown.

But in the book it says that if we convert array to list then the list will be immutable. So if we correct code ( line 7 instead of names.asList() to Array.asList())  then I assume it should throw an exception in runtime.