List of usage examples for java.util ArrayList add
public boolean add(E e)
From source file:Main.java
public static List<String> getZeroList(final int size) { final ArrayList<String> resList = new ArrayList<String>(size); for (int i = 0; i < size; i++) { resList.add("0"); }//from www .j ava 2 s. co m return resList; }
From source file:Main.java
/** * Materializes the elements of the given {@link Iterator} into a {@link List}. * //from www.j ava 2s . co m * @param <T> * the element type * @param iterator * the {@link Iterator} to materialize * @return the {@link List} containing the materialized elements. */ public static <T> List<T> asList(Iterator<T> iterator) { ArrayList<T> list = new ArrayList<T>(); while (iterator.hasNext()) list.add(iterator.next()); return list; }
From source file:Client.SessionService.java
public static SessionService create(String init_nickname) { ArrayList<String> keywords = new ArrayList<>(); keywords.add("session"); SessionService serv = new SessionService(keywords); serv.initname = init_nickname;/*from w w w .jav a 2s . co m*/ return serv; }
From source file:Main.java
/** * @param list An ArrayList to be expanded. * @param newCapacity The new capacity./* www .j a v a 2 s . c o m*/ */ public static void expandArrayListSize(final ArrayList<?> list, final int newCapacity) { while (list.size() < newCapacity) { list.add(null); } }
From source file:Main.java
public static List<Long> parseLongJsonList(JSONArray array) throws JSONException { if (array == null) { return new ArrayList<Long>(); }/* w ww . j a va 2s . c o m*/ int size = array.length(); ArrayList<Long> list = new ArrayList<Long>(size); for (int i = 0; i < size; i++) { list.add(array.getLong(i)); } return list; }
From source file:Main.java
public static <T, V extends T> ArrayList<T> createArrayList(V... args) { if ((args == null) || (args.length == 0)) { return new ArrayList(); }/*ww w . j av a 2s .c om*/ ArrayList<T> list = new ArrayList(args.length); for (V v : args) { list.add(v); } return list; }
From source file:Main.java
public static List<String> stringsToList(String[] arrayOfString) { if ((arrayOfString == null) || (arrayOfString.length == 0)) return null; ArrayList<String> list = new ArrayList<String>(); for (int i = 0; i < arrayOfString.length; i++) list.add(arrayOfString[i]); return list;//from ww w . j ava 2 s . c om }
From source file:Main.java
/** * @param integer The integer to be converted * @param n the number of bits of the output binary * @return Array of binary number where arr(0) is the most significant *//*from www . j ava2s. co m*/ public static ArrayList<Boolean> decimalToBinary(Integer integer, int n) { ArrayList<Boolean> result = new ArrayList(); if (integer == 0) { result.add(false); for (int i = 0; i < n - 1; i++) result.add(false); Collections.reverse(result); return result; } while (integer != 0) { if (integer % 2 != 0) result.add(true); else result.add(false); integer = integer / 2; } // Fill the rest of the bits for (int i = 0; i < (n - result.size()); i++) result.add(false); Collections.reverse(result); return result; }
From source file:Main.java
private static ArrayList<PointF> colorPointsForModel(String model) { // LLC001, // LedStrip // LWB001, // LivingWhite if (model == null) { // if model is not known go for the default choice model = " "; }/* w w w.j a v a2 s . c o m*/ ArrayList<PointF> colorPoints = new ArrayList<PointF>(); ArrayList<String> hueBulbs = new ArrayList<String>(); hueBulbs.add("LCT001"); ArrayList<String> livingColors = new ArrayList<String>(); livingColors.add("LLC001"); livingColors.add("LLC005"); livingColors.add("LLC006"); livingColors.add("LLC007"); livingColors.add("LLC010"); livingColors.add("LLC011"); livingColors.add("LLC012"); if (hueBulbs.contains(model)) { // Hue bulbs color gamut triangle colorPoints.add(new PointF(.674F, 0.322F)); // Red colorPoints.add(new PointF(0.408F, 0.517F)); // Green colorPoints.add(new PointF(0.168F, 0.041F)); // Blue } else if (livingColors.contains(model)) { // LivingColors color gamut triangle colorPoints.add(new PointF(0.703F, 0.296F)); // Red colorPoints.add(new PointF(0.214F, 0.709F)); // Green colorPoints.add(new PointF(0.139F, 0.081F)); // Blue } else { // Default construct triangle wich contains all values colorPoints.add(new PointF(1.0F, 0.0F));// Red colorPoints.add(new PointF(0.0F, 1.0F)); // Green colorPoints.add(new PointF(0.0F, 0.0F));// Blue } return colorPoints; }
From source file:Main.java
public static String getBreadcrumbs(final Activity activity) { Activity currentActivity = activity; ArrayList<String> breadcrumbs = new ArrayList<>(); while (currentActivity != null) { breadcrumbs.add(currentActivity.getTitle().toString()); currentActivity = currentActivity.getParent(); }//from ww w. ja va2 s . c o m return joinSlash(breadcrumbs); }