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
  • 1287
  • 1287


Add your comment
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.

Java EE7
Written by: Andrew Lee Rubinger
Featured Refcardz: Top Refcardz:
  1. Design Patterns
  2. OO JS
  3. Cont. Delivery
  4. CI Patterns
  5. CI Tools
  1. Spring Integration
  2. Git
  3. Regex
  4. Java
  5. REST