Example usage for java.util ArrayList add

List of usage examples for java.util ArrayList add

Introduction

In this page you can find the example usage for java.util ArrayList add.

Prototype

public boolean add(E e) 

Source Link

Document

Appends the specified element to the end of this list.

Usage

From source file:Main.java

@SuppressWarnings("unchecked")
public static String[] split(String str, String splitsign) {
    int index;//www. j  a v a  2 s  .c  o m
    if (str == null || splitsign == null)
        return null;
    ArrayList al = new ArrayList();
    while ((index = str.indexOf(splitsign)) != -1) {
        al.add(str.substring(0, index));
        str = str.substring(index + splitsign.length());
    }
    al.add(str);
    return (String[]) al.toArray(new String[0]);
}

From source file:Main.java

private static ArrayList<String> generateCharacters(int count) {
    ArrayList<String> characterPlayed = new ArrayList<>();
    for (int i = 0; i < count; i++) {
        characterPlayed.add(generateRandomString());
    }// ww w.ja v a2  s  . c o  m
    return characterPlayed;
}

From source file:Main.java

public static String[] getValueByGap(int max, int min, int gap) {

    ArrayList<String> list = new ArrayList<String>();
    for (int i = min; i <= max; i += gap) {
        list.add(String.valueOf(i));
    }/*  w  w  w  .  j  a va2  s .  c om*/
    String[] s = new String[list.size()];
    return list.toArray(s);
}

From source file:Main.java

public static List<Integer> toAbsIntegerList(final List<Integer> array) {
    final ArrayList<Integer> retValue = new ArrayList<Integer>();
    for (final Integer item : array)
        retValue.add(Math.abs(item));
    return retValue;
}

From source file:Main.java

/**
 * Creates a new list with elements being results of mapping
 * the function over the original list./*from ww w.j  ava2  s. co  m*/
 * @param xs original list
 * @param f function
 * @param <T> original list element type, also function parameter type
 * @param <U> function result type
 * @return list of results of mapping the function
 */
@Nonnull
public static <T, U> List<U> listMap(@Nonnull List<T> xs, @Nonnull Function<T, U> f) {
    ArrayList<U> result = new ArrayList<U>(xs.size());
    for (T x : xs) {
        result.add(f.apply(x));
    }
    return result;
}

From source file:Main.java

public static ArrayList<String> getCurrentWeek() {
    SimpleDateFormat format = new SimpleDateFormat("dd");
    Calendar calendar = Calendar.getInstance();
    calendar.setFirstDayOfWeek(Calendar.SUNDAY);
    calendar.set(Calendar.DAY_OF_WEEK, Calendar.SUNDAY);

    ArrayList<String> days = new ArrayList<String>();
    for (int i = 0; i < 7; i++) {
        days.add(format.format(calendar.getTime()));
        calendar.add(Calendar.DAY_OF_MONTH, 1);
    }// w ww.j a va 2 s . c  o  m
    return days;
}

From source file:Main.java

public static String[] split(String paramString1, String paramString2) {
    int i = paramString1.indexOf(paramString2);
    if (i == -1)//from   ww w  . j a  va  2  s.  c  om
        return new String[] { paramString1 };
    ArrayList localArrayList = new ArrayList();
    int j = 0;
    while (i != -1) {
        localArrayList.add(paramString1.substring(j, i));
        j = i + paramString2.length();
        i = paramString1.indexOf(paramString2, j);
    }
    if (j != paramString1.length())
        localArrayList.add(paramString1.substring(j));
    return (String[]) localArrayList.toArray(new String[localArrayList.size()]);
}

From source file:Main.java

public static Collection<String> splitStringBySize(String str, int size) {
    ArrayList<String> split = new ArrayList<>();
    for (int i = 0; i <= str.length() / size; i++) {
        split.add(str.substring(i * size, Math.min((i + 1) * size, str.length())));
    }//from   w  w w .  ja  va  2 s .  c o  m
    return split;
}

From source file:Main.java

public static ArrayList<String> getList(String source, String s) {
    String[] arr = source.split(s);
    ArrayList<String> list = new ArrayList<String>();
    for (String string : arr) {
        list.add(string);
    }// w ww  .j a  v a2s .  c  o m
    return list;
}

From source file:Main.java

public static NamespaceContext getNamespaceContext(final String prefix, final String uri) {
    return new NamespaceContext() {
        @Override/*w w w  .j a  v  a 2 s  .c  o m*/
        public String getNamespaceURI(String prefix) {
            return uri;
        }

        @Override
        public String getPrefix(String uri) {
            return prefix;
        }

        @Override
        public Iterator<String> getPrefixes(String uri) {
            ArrayList<String> prefixes = new ArrayList<String>();
            prefixes.add(prefix);
            return prefixes.iterator();
        }
    };
}