Here you can find the source of addToArray(String[] items, String str)
Parameter | Description |
---|---|
items | The array to append data in |
str | The string to append |
public static String[] addToArray(String[] items, String str)
//package com.java2s; /*//from w ww . j a va 2 s. c om * Copyright 2007-2012 The Europeana Foundation * * Licenced under the EUPL, Version 1.1 (the "Licence") and subsequent versions as approved * by the European Commission; * You may not use this work except in compliance with the Licence. * * You may obtain a copy of the Licence at: * http://joinup.ec.europa.eu/software/page/eupl * * Unless required by applicable law or agreed to in writing, software distributed under * the Licence is distributed on an "AS IS" basis, without warranties or conditions of * any kind, either express or implied. * See the Licence for the specific language governing permissions and limitations under * the Licence. */ import java.util.ArrayList; import java.util.Arrays; import java.util.List; public class Main { public static final String[] EMPTY_ARRAY = new String[] {}; /** * Adds a string to a string array. If the array is null it creates it * * @param items * The array to append data in * @param str * The string to append * @return The modified array */ public static String[] addToArray(String[] items, String str) { List<String> itemList; if (items == null) { itemList = new ArrayList<String>(); } else { itemList = new ArrayList<String>(Arrays.asList(items)); } if (str != null) { itemList.add(str); } return itemList.toArray(new String[itemList.size()]); } /** * Convert a list to array * * @param list * @return */ public static String[] toArray(List<String> list) { if (list != null && list.size() > 0) { return list.toArray(new String[list.size()]); } return EMPTY_ARRAY; } public static String[] toArray(String... items) { return items; } }