Contact@itspring.com
  • Java Program To Convert Int Array To String Array

    1. Using for loop :

    Basic solution to this problem is create an array of String type, then using for loop, assign values to it from integer array after converting int to strings.

    Here is the code :

    <p>&nbsp;/*Java program to convert int array to String array*/</p>
    <
    div>&nbsp;</div>
    <
    div>import java.util.Arrays;</div>
    <
    div>&nbsp;</div>
    <
    div>public class Demo {</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">    </span>public static void main(String[] args) {</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">        </span>// int array</div>
    <div><span style="white-space:pre">        </span>int[] intArray = { 1020304050 };</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">        </span>// print int array</div>
    <div><span style="white-space:pre">        </span>System.out.println(&quot;Integer Array&quot;);</div>
    <
    div><span style="white-space:pre">        </span>System.out.print(&quot;[ &quot;);</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">        </span>for (int i 0&ltintArray.lengthi++) {</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">            </span>System.out.print(intArray[i] + &quot; &quot;);</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">        </span>}</div>
    <
    div><span style="white-space:pre">        </span>System.out.println(&quot;] &quot;);</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">        </span>// create string array of same length</div>
    <div><span style="white-space:pre">        </span>String strArray[] = new String[intArray.length];</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">        </span>// convert int to string using valueOf() method</div>
    <div><span style="white-space:pre">        </span>for (int i 0&ltintArray.lengthi++) {</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">            </span>strArray[i] = String.valueOf(intArray[i]);</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">        </span>}</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">        </span>// Array converted to String</div>
    <div><span style="white-space:pre">        </span>System.out.println(&quot;After converting to String&quot;);</div>
    <
    div><span style="white-space:pre">        </span>System.out.println(Arrays.toString(strArray));</div>
    <
    div>&nbsp;</div>
    <
    div><span style="white-space:pre">    </span>}</div>
    <
    div>&nbsp;</div>
    <
    div>}</div>

Most Liked Posts

Post A Comment

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

JOAP

0 Comments

No Record found
demo content

The Total Economic Impactâ„¢ of ServiceNow

United States Tue Jun 06 2017

Join us for a webinar where we will reveal the quantified value of the Lightspeed Enterprise for customers that are modernizing IT, eliminating service outages, and optimizing performance with real-time analytics.

Guest speakers Liz Witherspoon of Forrester, and study participant Brad Paubel, VP of Internal Technologies at Maritz, will discuss

  • The value drivers for IT and key quantified economic benefits
  • Key challenges that study customers faced and overcame
  • Focus areas and best practices you can use to drive business impact with ServiceNow

Register

Webinar Registration

Enter the characters visible in the box below

IPJK

Share

Share using

Advertise With Us