Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can change from string to int in different ways as follows.</p> <pre><code>Integer.parseInt(arr[i].toString()); Integer.valueOf(arr[i].toString()).intValue(); Integer temp=new Integer(arr[i].toString()); </code></pre> <hr> <p>You can parse the elements of <code>arr[]</code> to <code>int</code> and store into another array as follows.</p> <pre><code>public class Main { public static void main(String args[]) { String s="1,2,3"; Object[] arr=s.split("\\,"); int temp[]=new int[arr.length]; for(int i=0; i&lt;arr.length; i++) { temp[i]=Integer.parseInt(arr[i].toString()); System.out.println(temp[i]); } } } </code></pre> <hr> <p>You can convert a data type to another data type as follows (using <em>auto-boxing</em> and <em>unboxing</em> techniques).</p> <pre><code> Float f=new Float(arr[0].toString()); f=Float.parseFloat(arr[0].toString()); f=Float.valueOf(arr[0].toString()).floatValue(); Double d=new Double(arr[0].toString()); d=Double.parseDouble(arr[0].toString()); d=Double.valueOf(arr[0].toString()).doubleValue(); Long l=new Long(arr[0].toString()); l=Long.parseLong(arr[0].toString()); l=Long.valueOf(arr[0].toString()).longValue(); Byte b=new Byte(arr[0].toString()).byteValue(); b=Byte.parseByte(arr[0].toString()); b=Byte.valueOf(arr[0].toString()).byteValue(); Short sh=new Short(arr[0].toString()); sh=Short.parseShort(arr[0].toString()); sh=Short.valueOf(arr[0].toString()).shortValue(); String str=String.valueOf(arr[0]).toString(); Boolean bool=true; String boolStr=bool.toString(); boolean boolPri=false; boolStr=String.valueOf(boolPri); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload