Tuesday, January 6, 2015

Performance Improvements StringBuilder and ArrayList and HashMap

Use StringBuilder if Synchronization is not required.

I have used StringBuffer when performing concatenations on string and is far better than using Immutable Strings in Java but if you don't need the synchronization, which most likely could be the case so use StringBuilder

Quote from StringBuilder API:
This class [StringBuilder] provides an API compatible with StringBuffer, but with no guarantee of synchronization. This class is designed for use as a drop-in replacement for StringBuffer in places where the string buffer was being used by a single thread (as is generally the case). Where possible, it is recommended that this class be used in preference to StringBuffer as it will be faster under most implementations.

Using ArrayList vs LinkedList

LinkedList is great when you don't know the size of the list as it helps.

The default initial capacity of an ArrayList is pretty small (10 from Java 1.4 - 1.7).
But since the underlying implementation is an array, the array must be re-sized if you add a lot of elements.
To avoid the high cost of resizing when you know you're going to add a lot of elements, construct the ArrayList with a higher initial capacity. What's important is to initialize the list when you know upfront the size of the ArrayList and if it is going to be more than 10

List catalogDataVOList = new ArrayList<CatalogDataVO>((int) resultCount);

Reference: http://stackoverflow.com/questions/322715/when-to-use-linkedlist-over-arraylist

Use HashMap vs Hashtable:
If Synchronization is not required use HashMap, Hashtable is a syncrhonized version and typically non synchronized objects perform better.

19 comments:

  1. The payday advance organizations guarantee that capable borrowers just utilize their administrations in crises - as opposed to utilizing them to cover regular costs, they say, individuals come to them when a startling issue comes up, for example, unanticipated auto repairs or a high quarterly bill.

    ReplyDelete
  2. So it is prudent to pick your bank carefully, by working out the net payable enthusiasm utilizing the online mini-computers for the most part gave by the loan specialists site.

    ReplyDelete
  3. Know about every one of the terms and conditions that may apply. The web makes correlation shopping simple; ensure you exploit this to spare a couple of dollars on charges every payday.

    ReplyDelete
  4. Startling costs manifest for everybody, and in spite of watchful budgetary administration a sudden auto repair charge or a very late chance to book a shabby occasion can scupper even the most reasonable of client's monetary plans.

    ReplyDelete
  5. Savage moneylenders are promptly accessible so take the time and contact no less than 3 unique organizations preceding being in a defenseless state.

    ReplyDelete
  6. Not long noticed concerning your web site and are still already reading along. I assumed i’ll leave my initial comment. i do not verify what saying except that I’ve enjoyed reading. Nice blog. ill be bookmarking keep visiting this web site really usually. https://royalcbd.com/product/cbd-gummies-10mg/

    ReplyDelete
  7. Me encanta el articulo, es super interesante y curioso, se lee genial con mucha fluidez. Estoy deseando leer más artículos vuestros, sois geniales.

    ReplyDelete
  8. Que buen blog tenéis, me encanta leer todos vuestros artículos es de los mejores blog. Además son super útiles y claros.

    ReplyDelete
  9. Es un blog muy interesante, me ha gustado mucho leerlo, ya que puede ser algo de gran utilidad para poner en práctica.

    ReplyDelete
  10. Enhorabuena por el artículo, muy buena redacción, se nota claramente que le pones esfuerzo y ganas.

    ReplyDelete
  11. Muy buen post, gracias por compartir esta información, sin duda seguiré esperando a que subas más contenido.

    ReplyDelete
  12. Muy chulo el artículo, contiene información muy interesante, gracias por tu interés.

    ReplyDelete
  13. Me encanta todo lo que cuentas en el post, es muy interesante y me encantaría que explicaras más sobre el tema.

    ReplyDelete
  14. No es lo que buscaba en estos momentos, pero me he parado a leerlo y me ha interesado más de lo que me esperaba , muchísimas gracias.

    ReplyDelete
  15. Buenas!! que interesante tu artículo, ha sido una información muy útil que estoy segura que usaré. Estoy deseando que subas nuevo contenido pronto. saludos <3

    ReplyDelete
  16. Me gusta mucho tu página en general y este artículo en particular me ha encantado, siento que le dedicas mucho tiempo y que disfrutas lo que haces. mucha suerte!!!

    ReplyDelete
  17. No se si estoy de acuerdo con todo lo que has escrito pero sin ninguna duda lo haces desde el respeto y la educación. Tener puntos de vista distintos a los míos es una oportunidad para poder aprender cosas nuevas. Deseando que subas más contenido. Un saludo!!!

    ReplyDelete
  18. No tenía mucha idea acerca del tema y la verdad es que vuestra información ha sido muy útil e instructiva, he aprendido muchas cosas que podré poner en práctica a partir de ahora. ¡Muchas gracias!

    ReplyDelete
  19. Las Vegas casinos with a $200M upgrade - Dr.
    LAS VEGAS (July 4, 2021) – 논산 출장안마 Las Vegas, Nevada 강원도 출장안마 (March 21, 2021) 구리 출장마사지 – Las Vegas, Nevada (March 21, 2021) – Las Vegas, Nevada (March 공주 출장샵 21, 2021) – Las Vegas, 나주 출장샵 Nevada (

    ReplyDelete