Solution:NIIT/GNIIT Sonugiri0032@gmail.com

Wednesday, January 06, 2016

How to convert a string from array list to array of char in Java | Array List to Array Java | Array list to Array string | Array List to Array Conversion in Java | Array List to Array example

How to convert a string from array list to array of char in Java | Array List to Array Java | Array list to Array string | Array List to Array Conversion in Java | Array List to Array example

The Program is about Array List and array in Java with GUI feature. The convert a string from array list to array of char and display the result in array of char. The array list is built-in data structure Java and very beneficial when we want to store data linearly or or data need indexing.

Source Code     

package lep;

import java.util.ArrayList;
/**
 * @author Uzair
 */
public class ArrayListToStringArray {

    public static void main(String args[]) {
        System.out.println("\n\n\n"
  +"\t*******************************************************\n"
  +"\t**                                                   **\n"
  +"\t**                   Welcome To                      **\n"
  +"\t**                                                   **\n"
  +"\t**         ArrayList<String> To String[]             **\n"
  +"\t**                                                   **\n"
  +"\t**              Conversion Program                   **\n"
  +"\t**                                                   **\n"
  +"\t*******************************************************\n");
        System.out.println("\t\t\t");
  
        //ArrayList<String> to store list of strings
        ArrayList<String> all_types = new <String>ArrayList();
        all_types.add("One");
        all_types.add("Two");
        all_types.add("Three");
        all_types.add("Other");
  
  //String[] is an array of string
        String[] itemArr = new String[all_types.size()];
        itemArr = all_types.toArray(itemArr);

        System.out.println(" Displaying String : ");
        for(String s : itemArr)
            System.out.println(s);
    }
    
}

Output of the Program

How to convert a string from array list to array of char in Java
Share:

0 comments:

GNIITSOLUTION GNIIT SOLUTION. Powered by Blogger.

Translate

Blog Archive

Unordered List