Before going to a java interview it's best to remember a few coding snippets that would greatly help you to compose your coding interview answers. Here are some coding snippets I have reached to, I encourage you to add in comments other snippets you think are important.
- String
- char c = s.charAt(2); // get char at location 2.
- “hamburger”.substring(4,8) // startindex0 so from idx 4 to idx 8
- Use StringBuilder for new string building setCharAt .append
- Map
- map.containsKey(k) // check if k is in map
- 537 % 10 # => 7 extract first digit from number
- 537 / 10 # => 53 remove first digit from number
- List
- add(index, element)
- set(index, element)
- remove(index)
- Random
- new Random.nextInt(10) // 0 - 9 (exclusive)
- Queue,Stack - start using those data structures!!
- Arrays:
- Copy
- System.arraycopy(source, startindex, dest, startindex, nToCopy)
- Arrays.toString(d.getArr())
BOOK: "Elements of Programming Interviews in Java: The Insiders' Guide" This is the best book I have found on java interview tips, if you are looking to concentrate on java this is by far the best resource on the subject.
Comments
Post a Comment