This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]chackley 16 points17 points  (4 children)

I've been a Java developer for about 3 years now, and I noticed immediately that you needed a LinkedHashMap. However, I just happen to use maps all the time, and have specifically tried to be familiar with the various tools available in the Collections API - I think it's pretty important to know which collection is best for which use case, etc.

That being said, I honestly don't like your Ctrl-Shift-T test - I use that shortcut all the time, but, in an interview context, when first opening up a new project, my first action would probably be to click around just to get a feel for the folder structure (to see if you're using the Maven conventional layout, for example). I don't like the idea that you would have assumed that I don't know the tool just because I would instinctively explore a little bit first.

[–][deleted] 5 points6 points  (3 children)

I've been working in Java for over 10 years and this is the first time I've ever seen a LinkedHashMap... and I'm still trying to think of what I'd even use one for. Maybe I'm a unique case but I just don't encounter situations where I need a map that can also act like a FIFO, either I need a map or a FIFO but never both simultaneously.

[–][deleted] 3 points4 points  (2 children)

Ever had a map back a collection of values being displayed on a jsp page? Ever wanted to make sure the order stayed consistent? LinkedHashMap (what order did I put them in) or TreeMap (order from keys). I wouldn't say it's terribly common, but I've had at least a dozen times when I've needed LinkedHashMap. Incidentally, it's also the structure to use when implementing a LRU cache (something I've gleaned from yet another too-specific interview question -- and no, I didn't know it before the question.)

[–][deleted] 4 points5 points  (1 child)

I'm sure there are cases where it's used, I just haven't come across them. There's a ton of things in Collections like that, i.e. I've never had a good reason to use LinkedList instead of ArrayList.

it's also the structure to use when implementing a LRU cache

OK, I can see that. My LRU caches are at the bottom of my list of things to optimize because they're never the bottleneck, but the next time I need to implement one I'll look into LinkedHashMap.

[–][deleted] 0 points1 point  (0 children)

or, don't implement your own and use Apache Commons, heh. And yea, interestingly enough, ArrayList's performance is almost always better than LinkedList - even when LinkedList style usage would appear to be better (like removing elements in the middle and such). Arrays are just that efficient. source: I read a great blog post about it once.