Convert Boolean ArrayList to Boolean List in Java Android

How to change Boolean true,false to array list true false and show on activity screen using textview.

Boolean values are true and false and they can also change into Boolean array list to Boolean array. So here is the complete step by step tutorial for Convert Boolean ArrayList to Boolean List in Java Android.

android-project-download-code-button

How to Convert Boolean ArrayList to Boolean List in Java Android.

Code for MainActivity.java file.

 package com.convertbooleanarraylisttobooleanlist_android_examples.com;

import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {

 //Initializing Boolean array list;
 List<Boolean> BooleanArrayList = new ArrayList<>();
 
 //Initializing Boolean array;
 Boolean[] BooleanArray;
 
 //Initializing TextView
 TextView textview1,textview2;
 
 int i,j = 0;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 textview1 = (TextView)findViewById(R.id.textView1);
 textview2 = (TextView)findViewById(R.id.textView2);
 
 //Adding values to Boolean array list.

 BooleanArrayList.add(Boolean.TRUE);
 BooleanArrayList.add(Boolean.FALSE);
 BooleanArrayList.add(true);
 BooleanArrayList.add(false);

 
 //Printing Boolean array list on screen using loop.
 
 textview1.setText("Boolean Array list : ");
 
 while ( i<BooleanArrayList.size() )
 {
 
 textview1.setText(textview1.getText() + " " + BooleanArrayList.get(i) + ", ");
 
 i++;
 
 }
 
 //Converting Boolean array list into Boolean array.
 BooleanArray = BooleanArrayList.toArray(new Boolean[BooleanArrayList.size()]);
 
 textview2.setText("Convert into Boolean Array : ");
 
 
 //Displaying converted Boolean array on screen using textview.
 while ( j<BooleanArray.length )
 { 
 textview2.setText(textview2.getText() + " " + BooleanArray[j] + ", ");
 
 j++;
 
 }
 
 }
}

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.convertbooleanarraylisttobooleanlist_android_examples.com.MainActivity" >

 
 <TextView
 android:id="@+id/textView2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_below="@+id/textView1"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="65dp"
 android:text="Boolean Array"
 android:gravity="center"
 android:textAppearance="?android:attr/textAppearanceLarge" />

 <TextView
 android:id="@+id/textView1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:gravity="center"
 android:text="Boolean ArrayList"
 android:textAppearance="?android:attr/textAppearanceLarge" />
 
 
</RelativeLayout>

Screenshot:

Convert Boolean ArrayList to Boolean List in Java Android

Click here to download Convert Boolean ArrayList to Boolean List in Java Android project with source code.

Leave a Reply

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