List of usage examples for java.util ArrayList add
public boolean add(E e)
From source file:Main.java
public static <T> ArrayList<T> inter(Collection<T> l1, Collection<T> l2) { ArrayList<T> l = new ArrayList<>(); for (T e : l1) { if (l2.contains(e)) { l.add(e); }/*from w ww . j a va 2 s .c o m*/ } return l; }
From source file:Main.java
public static List stringsToList(String as[]) { Object obj;/*from www. ja va 2 s . c o m*/ if (as == null || as.length == 0) { obj = null; } else { ArrayList arraylist = new ArrayList(); for (int i = 0; i < as.length; i++) arraylist.add(as[i]); obj = arraylist; } return ((List) (obj)); }
From source file:Main.java
public static <T> List<T> toList(Collection<T> collection) { if (collection == null) { return new ArrayList<T>(); }/*from w w w .j av a2 s. c o m*/ ArrayList<T> result = new ArrayList<T>(); for (T item : collection) { result.add(item); } return result; }
From source file:Main.java
/** * convert to List<T> from Enumeration<T> * /* w ww . ja v a 2 s.c o m*/ * @param enumeration * @return */ public static <T> List<T> convert(Enumeration<T> enumeration) { if (enumeration == null) { return Collections.emptyList(); } ArrayList<T> result = new ArrayList<T>(); while (enumeration.hasMoreElements()) { result.add(enumeration.nextElement()); } return result; }
From source file:Main.java
public static <T> List<T> subList(List<T> src, int start, int end) { ArrayList<T> result = new ArrayList<T>(); for (int i = start; i <= end && i < src.size(); i++) { result.add(src.get(i)); }/*from w w w . j a va 2 s . c o m*/ return result; }
From source file:Main.java
public static ArrayList<String> lineRepeat(String line, int count) { ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < count; i++) list.add(line); return list;/*from ww w .java 2 s . c o m*/ }
From source file:Main.java
public static HashMap<String, List<Object[]>> getUnitDataMapList(List<Object[]> list, int[] indexnum) { HashMap<String, List<Object[]>> dataMap = new HashMap<String, List<Object[]>>(); for (int i = 0; i < list.size(); i++) { StringBuffer returnStringBuffer = new StringBuffer(); for (int ai = 0; ai < indexnum.length; ai++) { int index = indexnum[ai]; Object obj = list.get(i)[index]; String gunit = obj.toString(); if (ai == 0) { returnStringBuffer.append(gunit); } else { returnStringBuffer.append("(" + gunit + ")"); }/*from ww w.j a v a 2 s . com*/ } String unit = returnStringBuffer.toString(); if (dataMap.containsKey(unit)) { dataMap.get(unit).add((Object[]) list.get(i)); } else { ArrayList<Object[]> rowdata = new ArrayList<Object[]>(); rowdata.add((Object[]) list.get(i)); dataMap.put(unit, rowdata); } } return dataMap; }
From source file:Main.java
public static <T> ArrayList<T> newArrayList(T[] initData) { ArrayList<T> ret = new ArrayList<T>(initData.length); for (T t : initData) { ret.add(t); }/*from ww w. j av a 2 s . c o m*/ return ret; }
From source file:Main.java
public static Intent share(String text, String mimeType, Uri... attachments) { final Intent intent = new Intent(); intent.setType(mimeType);//www . j a v a 2s. com if (attachments.length > 1) { intent.setAction(Intent.ACTION_SEND_MULTIPLE); final ArrayList<CharSequence> textExtra = new ArrayList<>(); textExtra.add(text); intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, textExtra); final ArrayList<Parcelable> uris = new ArrayList<>(); Collections.addAll(uris, attachments); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } else { intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, text); intent.putExtra(Intent.EXTRA_STREAM, attachments[0]); } return intent; }
From source file:Main.java
public static Intent share(String text, String mimeType, Uri... attachments) { final Intent intent = new Intent(); intent.setType(mimeType);//from ww w .j a v a 2s . com if (attachments.length > 1) { intent.setAction(Intent.ACTION_SEND_MULTIPLE); final ArrayList<CharSequence> textExtra = new ArrayList<>(); textExtra.add(text); intent.putCharSequenceArrayListExtra(Intent.EXTRA_TEXT, textExtra); final ArrayList<Parcelable> uris = new ArrayList<>(); Collections.addAll(uris, attachments); intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris); } else { intent.setAction(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, text); if (attachments.length > 0) { intent.putExtra(Intent.EXTRA_STREAM, attachments[0]); } } return intent; }