sorry .. the "Orthogonality Freak" again ... the (mock) exam builders tend to trick you by trying to get you to accept wrong syntax for any kind of "length" operations
So far I came across ..
Then you get presented with stuff like al.lenght and "Ha Ha Ha .. you're wrong .. see the API" (which contains thousands of methods .."
More or less three forms of syntax for more of less the same semantics - is there any "rationale" behind this or is it again - get yourself an Asperger diagnosis,
shut up and learn the phone directory ;-)?
For array the omission of the brackets is somehow a bit bumnpy
For a Set size() would be intuitive - as the ArrayList is a Collection - then size() makes sense - but is not what spontaneusly comes to your mind for a Array .. List :-)
Anyway - I'll have to "learn it verbatim"
Thanks to you all
Maybe because there are old, traditional names for those actions going back to before Java®. Words like push pop and peek, which is what you do to stacks, or offer and poll (queues) and add or remove (lists and sets) are widely used, but with practice you will become familiar with them. I am afraid there is no substitute for lots of practice; you can't expect to learn them all quickly.
I am afraid you are going to have to learn you r way round the API documentation too. It isn't that difficult; there probably aren't even a million methods to search through. But you can start by going to String where you will find two links called “METHODS” near the top. Click that nearer the left, and you get to the method summary, and by scrolling down to L, you will find the length() method. Read what it says both there and when you click on length which takes you to a fuller explanation. Read what you can understand and ask about wht you can't understand.
Also: don't try to learn the documentation off by heart or memorise any of it. If you have to look the same thing up 10× an hour, look it up 10×.
Some of them have been largely sorted out, for example by replacing Date/Calendar with LocalDate, etc., Some haven't. Joshua Bloch says somewhere (Effective Java 2/e page 86) that there are problems with the design of classes like Stack and Properties. I use stacks in Forth, so I think they have never really corrected Stack.
Jesper de Jong wrote:. . . inconsistent naming and poorly designed classes and interfaces. . . .
It is possible to design an advanced stack with more operations; Forth stacks support about ten or twelve more. But none does anything to the bottom of the stack.
Java 8 API Docs wrote:Deques can also be used as LIFO (Last-In-First-Out) stacks. This interface should be used in preference to the legacy Stack class. When a deque is used as a stack, elements are pushed and popped from the beginning of the deque. Stack methods are precisely equivalent to Deque methods as indicated in the table below:
Comparison of Stack and Deque methods
Stack Method Equivalent Deque Method push(e) addFirst(e) pop() removeFirst() peek() peekFirst()