List of usage examples for java.util ArrayList size
int size
To view the source code for java.util ArrayList size.
Click Source Link
From source file:Main.java
public static void main(String[] args) { ArrayList<String> arrayList = new ArrayList<String>(); arrayList.add("1"); arrayList.add("2"); arrayList.add("3"); System.out.println(arrayList.size()); arrayList.clear();/*from www . j a v a 2s . c om*/ System.out.println(arrayList.size()); }
From source file:Main.java
public static void main(String[] args) { ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(15);//w w w .ja va2s. com arrlist.add(2); arrlist.add(2); arrlist.add(2); int retval = arrlist.size(); System.out.println("Size of list = " + retval); }
From source file:SearchTest.java
public static void main(String args[]) { String simpsons[] = { "Bart", "Hugo", "Lisa", "Marge", "Homer", "Maggie", "Roy" }; // Convert to list ArrayList list = new ArrayList(Arrays.asList(simpsons)); // Ensure list sorted Collections.sort(list);//from w ww. ja v a 2 s. co m System.out.println("Sorted list: [length: " + list.size() + "]"); System.out.println(list); // Search for element in list int index = Collections.binarySearch(list, "Maggie"); System.out.println("Found Maggie @ " + index); // Search for element not in list index = Collections.binarySearch(list, "Jimbo Jones"); System.out.println("Didn't find Jimbo Jones @ " + index); // Insert int newIndex = -index - 1; list.add(newIndex, "Jimbo Jones"); System.out.println("With Jimbo Jones added: [length: " + list.size() + "]"); System.out.println(list); }
From source file:MainClass.java
public static void main(String[] args) { ArrayList myList = new ArrayList(5); for (int i = 0; i < 5; i++) { myList.add(new Integer(i)); }/* w ww . ja v a 2s. com*/ System.out.println("List contains " + myList.size() + " elements"); Integer int2 = new Integer(2); System.out.println("List contains Integer(2): " + myList.contains(int2)); System.out.println("Integer(2) is at index " + myList.indexOf(int2)); myList.set(2, new Integer(99)); System.out.println("Get element at index 2: " + myList.get(2)); myList.ensureCapacity(15); for (int i = 10; i < 15; i++) { myList.add(new Integer(i)); } myList.subList(10, 15).clear(); myList.trimToSize(); System.out.println(myList); }
From source file:Main.java
public static void main(String[] args) { ArrayList<Integer> arrlist = new ArrayList<Integer>(5); arrlist.add(20);//from ww w . j ava2 s .co m arrlist.add(15); arrlist.add(30); arrlist.add(45); System.out.println("Size of list: " + arrlist.size()); System.out.println(arrlist); arrlist.remove(2); System.out.println("Size of list: " + arrlist.size()); System.out.println(arrlist); }
From source file:fitmon.DietAPI.java
public static void main(String[] args) throws InvalidKeyException, NoSuchAlgorithmException, ParserConfigurationException, SAXException, IOException { DietAPI obj = new DietAPI(); ArrayList<Food> foodList = new ArrayList<Food>(); ArrayList<ArrayList<Food>> listOfFoodList = obj.searchFood("apple"); for (int i = 0; i < listOfFoodList.size(); i++) { for (int j = 0; j < listOfFoodList.get(i).size(); j++) { foodList.add(listOfFoodList.get(i).get(j)); }//from www .j a va 2 s . c om } }
From source file:Main.java
public static void main(String[] args) { ArrayList<String> al = new ArrayList<String>(); al.add("Java"); al.add("SQL"); al.add("Data"); System.out.println("ArrayList:" + al); String[] s1 = new String[al.size()]; String[] s2 = al.toArray(s1); System.out.println("s1 == s2:" + (s1 == s2)); System.out.println("s1:" + Arrays.toString(s1)); System.out.println("s2:" + Arrays.toString(s2)); s1 = new String[1]; s1[0] = "hello"; // Store hello in first element s2 = al.toArray(s1);/* ww w . j a v a 2s . c o m*/ System.out.println("s1 == s2:" + (s1 == s2)); System.out.println("s1:" + Arrays.toString(s1)); System.out.println("s2:" + Arrays.toString(s2)); }
From source file:ArrayListToArray.java
public static void main(String args[]) { ArrayList<Integer> al = new ArrayList<Integer>(); al.add(1);/*w w w . ja v a2 s. co m*/ al.add(2); al.add(3); al.add(4); System.out.println("Contents of al: " + al); Integer ia[] = new Integer[al.size()]; ia = al.toArray(ia); int sum = 0; for (int i : ia) sum += i; System.out.println("Sum is: " + sum); }
From source file:MainClass.java
public static void main(String args[]) { ArrayList<Integer> al = new ArrayList<Integer>(); al.add(1);/*from w w w . j a v a2 s .co m*/ al.add(2); al.add(3); al.add(4); System.out.println("Contents of al: " + al); Integer ia[] = new Integer[al.size()]; ia = al.toArray(ia); int sum = 0; for (int i : ia) sum += i; System.out.println("Sum is: " + sum); }
From source file:MainClass.java
public static void main(String[] args) { // Build a vector of words to be sorted ArrayList list = new ArrayList(); list.add("m"); list.add("c2"); list.add("e"); list.add("c1"); Collator collate = Collator.getInstance(); CollationKey[] keys = new CollationKey[list.size()]; for (int k = 0; k < list.size(); k++) keys[k] = collate.getCollationKey((String) list.get(k)); Arrays.sort(keys);//from w ww. j a v a 2 s.com for (int l = 0; l < keys.length; l++) { System.out.println(keys[l].getSourceString()); } }