Link Details

Link 785303 thumbnail
User 312347 avatar

By saimatam
Published: May 03 2012 / 09:57

While browsing Java sources, I came accross an interesting code fragment that I thought I would share with you. This piece of code formats an integer array to string. I felt that the way the for loop is structured is very unusual. I wrote a similar method to compare our approaches. In this article I present both these versions.
  • 9
  • 2
  • 1380
  • 1287
User 852717 avatar

Kazi Abdullah Saikat replied ago:

0 votes Vote down Vote up Reply

All the solutions will work and work well with little difference in performance.
However, I must stress that the JDK version "avoids" GE or LE check and only uses an EQ check since EQ check in theory should run faster :-)
Also having a 'size - 1' in the for loop condition means that it will be re-evaluated multiple times (in theory at-least).

Add your comment

Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.

Apache Hadoop
Written by: Piotr Krewski
Featured Refcardz: Top Refcardz:
  1. Play
  2. Akka
  3. Design Patterns
  4. OO JS
  5. Cont. Delivery
  1. Play
  2. Java Performance
  3. Akka
  4. REST
  5. Java