Show transcribed image text
Expert Answer
- Comment
//StringToArrayList.java import java.util.ArrayList; import java.util.Scanner; public class StringToArrayList { public static ArrayList<Character> toCharacterArray(String s){ ArrayList<Character> list = new ArrayList<Character>(); for(char ch: s.toCharArray()){ list.add(ch); } return list; } public static void main(String args[]) { String s; Scanner scanner = new Scanner(System.in); System.out.print("Enter input string: "); s = scanner.nextLine(); ArrayList<Character> list = toCharacterArray(s); System.out.print("Elements of the character array list: "); for(int i = 0;i<list.size();i++){ System.out.print(list.get(i) + " "); } } }
ليست هناك تعليقات:
إرسال تعليق