import java.util.*; public class Cast { public static void main(String args[]) { // Configure the "input" List list = new ArrayList(); list.add("The "); list.add(new Integer(35)); list.add("quick "); list.add(new Double(Math.PI)); list.add("brown "); list.add(new java.awt.Point(1, 2)); list.add("fox "); list.add(new Float(89.124f)); list.add("jumps "); list.add("over "); list.add(new Short((short)14)); list.add("the "); list.add(new Byte((byte)12)); list.add("lazy "); list.add("sleeping "); list.add(new Long(9012)); list.add("dog."); // Get an iterator for the input list Iterator it = list.iterator(); // Create a StringBuffer to store // the concatenated elements StringBuffer sb = new StringBuffer(); // Initialize a variable to store the sum double sum = 0; // Loop through the list using the iterator while(it.hasNext()) { // Get the next element Object next = it.next(); // Check for type if (next instanceof Number) { // Sum up the numbers. Number num = (Number)next; sum += num.doubleValue(); } else if (next instanceof String) { // Combine the strings sb.append((String)next); } else { // ignore } } // Display the results System.out.println("Sentence: " + sb.toString()); System.out.println("Sum: " + sum); } }