|
Answer» • Create copies of simple array by initializing them through loops or by using System.arraycopy(), create copies of COMPLEX arrays by cloning them.
• Iterator.hasNext() and Enumerator.hasMoreElements() need not be repeatedly called when the size of the collection is known. Use collection.size() and a loop counter instead.
• ArrayList is faster than Vector
• Go for a non-synchronized version of collection unless used in a threaded application
• LinkedList is faster than ArrayList for inserting elements to the front of the array, but slower at indexed lookup.
• Accessing arrays is much faster than accessing vectors, String, and StringBuffer
• Vector is convenient to use, but inefficient. Ensure that elementAt() is not used inside a loop.
• Re-use Hashtables by using Hashtable.clear().
• Removing elements from a Vector will necessitate copying within the Vector if the element is removed from anywhere other than the end of the collection.
• Presizing collections to the expected size is more efficient than using the default size and letting the collection GROW.
• For multidimensional arrays store a reference for the currently accessed row in a variable.
• When ADDING MULTIPLE items to a collection, add them all in one CALL if possible. • Create copies of simple array by initializing them through loops or by using System.arraycopy(), create copies of complex arrays by cloning them.
• Iterator.hasNext() and Enumerator.hasMoreElements() need not be repeatedly called when the size of the collection is known. Use collection.size() and a loop counter instead.
• ArrayList is faster than Vector
• Go for a non-synchronized version of collection unless used in a threaded application
• LinkedList is faster than ArrayList for inserting elements to the front of the array, but slower at indexed lookup.
• Accessing arrays is much faster than accessing vectors, String, and StringBuffer
• Vector is convenient to use, but inefficient. Ensure that elementAt() is not used inside a loop.
• Re-use Hashtables by using Hashtable.clear().
• Removing elements from a Vector will necessitate copying within the Vector if the element is removed from anywhere other than the end of the collection.
• Presizing collections to the expected size is more efficient than using the default size and letting the collection grow.
• For multidimensional arrays store a reference for the currently accessed row in a variable.
• When adding multiple items to a collection, add them all in one call if possible.
|