Android examples for java.util:List Convert
Converts from an Object to a String List
/*/*from w w w . j a va2s . c o m*/ * Copyright (C) 2008-2012 Open Wide SA * * This library is free software; you can redistribute * it and/or modify it under the terms of version 2.1 of * the GNU Lesser General Public License as published by * the Free Software Foundation. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General * Public License along with this library; if not, write to the * Free Software Foundation, Inc., 59 Temple Place, Suite 330, * Boston, MA 02111-1307 USA * * More information at http://knowledge.openwide.fr/bin/view/Main/AlfrescoETLConnector/ */ import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; public class Main{ public static void main(String[] argv){ List values = java.util.Arrays.asList("asdf","java2s.com"); System.out.println(toStringList(values)); } /** * Converts from an Object to a String List * * @param values * @return * @throws AcpXmlException if a value is not a String (null not allowed) */ public static List<String> toStringList(List<Object> values) throws AcpXmlException { ArrayList<String> stringValues = new ArrayList<String>( values.size()); for (Object value : (List<Object>) values) { if (value instanceof String) { stringValues.add((String) value); continue; } throw new AcpXmlException("Value " + value + " of list " + values + " should be of type String"); } return stringValues; } }