Convert integer value into string in android

How to use String.valueOf( int value ) and Integer.toString( int value ) function in android.

There are some functions like toast message printing and other gives errors in your activity because you have directly used integer value on it and they don’t have to right ability to display integer values so you need to change int type values to string this process are called as type casting in android. So here is the complete step by step tutorial for Convert integer value into string in android .android-project-download-code-button

Convert integer value into string in android .

Code for MainActivity.java file.

package com.android_examples.com.convertintintostring;
import android.app.Activity;
import android.os.Bundle;
import android.widget.Toast;

public class MainActivity extends Activity {

 int a=101;
 
 // Both function Integer.toString(int value) and String.valueOf(int value) function is used to change integer value into string value.

 String b= Integer.toString(a);
 String c= String.valueOf(a);
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 Toast.makeText(MainActivity.this,b, Toast.LENGTH_LONG).show();
 
 }
}

Code for activity_main.xml layout file.

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="match_parent"
 android:paddingBottom="@dimen/activity_vertical_margin"
 android:paddingLeft="@dimen/activity_horizontal_margin"
 android:paddingRight="@dimen/activity_horizontal_margin"
 android:paddingTop="@dimen/activity_vertical_margin"
 tools:context="com.android_examples.com.convertintintostring.MainActivity" >

</RelativeLayout>

Screenshot:

Convert integer value into string in android

Click Here To Download Convert integer value into string in android Project.