sublist « ArrayList « Java Collection Q&A

Home
Java Collection Q&A
1.algorithm
2.array
3.Array Byte
4.Array Char
5.Array Convert
6.Array Dimension
7.Array Integer
8.Array Object
9.Array String
10.ArrayList
11.collection
12.comparator
13.Development
14.Garbage Collection
15.Generic
16.hash
17.HashMap
18.HashTable
19.iterator
20.LinkedList
21.List
22.Map
23.queue
24.Set
25.Sort
26.tree
Java Collection Q&A » ArrayList » sublist 

1. How to take a valid sublist in Java?    stackoverflow.com

I have this weird (I think) problem in Java. I have an ArrayList and I want to take a sublist. But I get the follow exception.

package javatest;

import java.util.ArrayList;

public class JavaTest {

   ...

2. Does sublist(from,to).clear() allow garbage collection of the cleared part of an ArrayList?    stackoverflow.com

In Java, when having some non-empty ArrayList, does

list.sublist(from,to).clear()
edit (refactored question): reduce the internal size of the ArrayList (i.e. let the ArrayList use less memory afterwards)? I am particularly interested in the case where ...

3. sublist of arraylist???    coderanch.com

import java.util.List; import java.util.ArrayList; public class SLTest { public static void main(String[] args) { List list = new ArrayList(); list.add("a"); list.add("b"); list.add("c"); list.add("d"); list.add("e"); printList(list); List sub = list.subList(1, 4); printList(sub); } public static void printList(List aList) { for (int i = 0; i < aList.size() - 1; i++) { System.out.print(aList.get(i) + ", "); } System.out.print(aList.get(aList.size() - 1) + "\n"); } ...

4. ArrayList subList    forums.oracle.com

snguyen wrote: Why do I get a ClassCastException here? Because the return value of subList() is not ArrayList and ArrayList.subList() does indeed not return an ArrayList at all (it couldn't easily do this and still conform to the contract of subList()). subList() returns a List and that should be sufficient. There isn't anything terribly important that you can do with an ...

5. ArrayList.subList() problem    forums.oracle.com

okay. what the code should do is create a temporary TreeSet() with only 5 items from the call to subList(). when i output what is stored in the TreeSet() i am getting from 4 to 5 items. for example: 0 // j = 0; [Hearts 5, Hearts 6, Spades 8, Diamonds Jack] Hearts 5 Hearts 6 Spades 8 Diamonds Jack 5 ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.