Example CodeJavaTips

String Utility Methods: Converting int[] to String

1 Mins read
java array tostring, convert java array to string, convert array to string, toString() method for array, array utility method convert to string, print array as string, string from array, convert array into string
Java has many in built operations supported by String class. There are few functions which I observed commonly used and may be helpful to keep handy as StringUtil class with static methods. I have already posted a toString() method for an Object array. Below is a utility method which can be used to display the array of int in String format, just like we can display Collections. The Java collections framework has toString method implemented for all its collections, but if we are utilizing a int array instead then converting the whole array to String has to be done a separate method along with writing toString() method for class. Below method can be called to convert the array to String representation same as collections. This will return a string with values separated by comma.  

* This method iterates over the array of int data to comma separated String


* As an example : <blockquote>


* <pre>

* int []lmn = {1,2,3,4,5};

* The output achieved is : 1,2,3,4,5

* </pre>


* </blockquote>


* @param intArray

* The int array

* @return Concatenated string


public static String toString(int[] intArray) {

String separator =


StringBuilder sb =

new StringBuilder(“”);

if (intArray != null && intArray.length > 0) {

for (int i = 0; i < intArray.length; i++) {


if (i < (intArray.length – 1)) {





return sb.toString();


Related posts

3 Tips to Troubleshoot Readiness Probe Failed Errors Effectively : Kubernetes

4 Mins read
A Kubernetes readiness probe can improve your service‚Äôs quality and reduce operational issues, making your service more resilient and robust. However, the…

Is It good to Wear Eyeglasses for Software Engineers?

2 Mins read
As technology continues to be a fundamental tool in our day-to-day lives, we spend more time staring at digital screens. This may…

The 3 Things It Takes To Become A Digital Nomad

3 Mins read
There is so little reason to sit in a cubicle in an office that takes hours out of your day commuting to…
Power your team with InHype

Add some text to explain benefits of subscripton on your services.

Leave a Reply

Your email address will not be published. Required fields are marked *