Writing Efficient Code (in Java) #### Looking things up Don't ask arrays/lists to do "contains()" Watch out for LinkedList.get(i). Hashtables as functions arrays as functions boolean[] charIsSpecial = new boolean[255]; charIsSpecial['.'] = true; charIsSpecial[';'] = true; arrays allocate then ZERO all the memory; expensive. Reuse arrays if you can. #### Sorting Insertion sort Radix sort using hashtable #### Java library stuff Strings (+ operator) make sure to close java sockets, files. #### Input, Output Used buffered IO read all into memory if you can (unless really big) #### Memory allocation Arrays are initialized to 0 Don't forget to release memory (ptr=null) #### Recursion Useful but can be expensive as hell #### Misc Witchel asked about a loop that must only run for n seconds. He was very worried about a loop expr "while ((System.currentTimeInMillis()-start)>n*1000)" or whatever. I told him to use a boolean !done test and then launch a timeout thread that sleeps n seconds and then sets done to true.