You are on page 1of 2

Collections and Data Structures

Allocation in memory while array construction


int[][] myArray = new int[3][];
only the first brackets are given a size. That's acceptable in Java, since the JVM needs to know only the size of the
object assigned to the variable myArray
Array assignments: primitive arrays could not be promoted to be assigned/(Eg byte array to int array npt psbl)
Arrays that hold object references can allow such promotion with is a test.

Implementing queues,stacks using arraylist,linkedlists


when to use arraylist and when linked list
Implement blocking/non blocking queue
implement sorting
how to traverse a binary search tree
fhow to make and traverse linked list
how to override equals method
diff b/w hashtable and hashmap, ,their underlying data structure
Where would u override equals and hashcode both
Initialize collections to an appropriate size for their use.
When a collection resizes, considerable CPU (and sometimes memory) is consumed.

ArrayList = new Arraylist() What is default initial capacity how does it improve
Load Factor nitial capacity
synchronized vs Cocnurrent map
What type of algo is used by Collections.sort, Arrays.sort (Insertion and later merge)
Comparable/Comparator
Priority Queue Implementation
Internal weakening of hashset/hashmap
How to have more than one parameter sorting in jst one class?
if hv a hashcode method which always return 1? Can I hv ? if yes wat can be the pitfalls of it and how wud u
overcome?
th

Onsert in 69 pos in 100 element araylist


Hascode compiled two times.
http://www.xyzws.com/javafaq/why-always-override-hashcode-if-overriding-equals/20
Legal but long linklist rtrieval and performance hit
In Java, every object has access to the equals() method because it is inherited from the Object class. However, this
default implementation just simply compares the memory addresses of the objects. You can override the default
implementation of the equals() method defined in java.lang.Object. If you override the equals(), you MUST also
override hashCode(). Otherwise a violation of the general contract for Object.hashCode will occur, which can have
unexpected repercussions when your class is in conjunction with all hash-based collection
http://java-performance.info/hashcode-method-performance-tuning/
the hashCode method defined by class Object does return distinct integers for distinct objects. (This is typically
implemented by converting the internal address of the object into an integer
http://stackoverflow.com/questions/2265503/why-do-i-need-to-override-the-equals-and-hashcode-methods-in-java

Object.hashcode() is a native method.


public native int hashCode();
That means it's implemented in platform specific code and is exposed as a native method.
code for the same will be a compiled code and not available withing JDK

when to override equals


if you want objects of your class to be used as keys for a
hashtable (or as elements in any data structure that uses equivalency for searching
forand/or retrievingan object), then you must override equals() so that two
different instances can be considered the same

You might also like