List.clear() outside of List finalList = new ArrayList(); will delete element in finalList?

Hello all!
I am using 3 ArrayLists.
the first is List<String>
the second is List<String[]>
and the third is a list of those lists List<List>
I use the first list to get the string I need, but I use the second for String.split.
I then need to keep a list of these to use, so I need the third List.
After adding the second list to the list of lists I want to clear it so I can set up the next list to be added, but if I do list.clear(); it will delete everything in that list.
If I do not clear it, it is fine.
At first I wasn't sure if it was my fault, because I'm not sure if I ever had to do that before, so I made a test case that yields the result if I change the element outside.
* To change this template, choose Tools | Templates
* and open the template in the editor.
package javaapplication1;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
* @author Konrad
public class JavaApplication1 {
     * @param args the command line arguments
    String a;
    List<String> j = new ArrayList<>();
    public JavaApplication1()
        a();
    public void a()
        a = "ADASDSADSA";
        j.add(a);
        a = null;
        System.out.println(j);
    public static void main(String[] args) throws SQLException {
        JavaApplication1 a = new JavaApplication1();
If I change a = null to a = ""; it still yields the original a = "ADASD......";
    protected List<String> list = new ArrayList<>();
    protected List<String[]> list2 = new ArrayList<>();
    protected List<List> finalList = new ArrayList<>();
  finalList.add(list2);
                 //list2.clear();
With this I yield an empty array element, even though my array elements exist.  I tried using multiple lists and I just had multiple empty elements.
So again I'm not sure if I did something wrong, or is this a bug?  Since my test case worked, I'm confused.
Thanks!
~KZ

After adding the second list to the list of lists I want to clear it so I can set up the next list to be added, but if I do list.clear(); it will delete everything in that list.
Correct - you are just working with multiple references to the SAME set of objects.
Use 'remove' to remove an element from a list and then 'add' to add it to the other list.
See the Javadocs for the 'remove' method of the List interface
http://docs.oracle.com/javase/6/docs/api/java/util/List.html#remove(int)
remove
E remove(int index)
Removes the element at the specified position in this list (optional operation). Shifts any subsequent elements to the left (subtracts one from their indices). Returns the element that was removed from the list.   
Parameters: 
index - the index of the element to be removed 
Returns: 
the element previously at the specified position 
Throws: 
UnsupportedOperationException - if the remove operation is not supported by this list 
IndexOutOfBoundsException - if the index is out of range (index < 0 || index >= size())

Similar Messages

  • I have collected alot of music over the years and the new update will delete all my music.  I have puchased a new computer about a year ago so the previous music that I have is not available.  Is there anyway to get the update and not lose all my music

    I have collected alot of music over the past couple years and the new update for the itouch says that it will erase all music and videos on the ipod.  Is there anyway to do the update and not lose all my music or is there a way to take all the music off my ipod and store it on my computer to put back on after the update?  Any help

    ... I have had numerous computers over the past years
    Let me guess, you have had numerous Windows computers, all of which crashed or became worthless virus-ridden junk. Happens every day, yet people think Macs are expensive.
    Anyway, you are going to need the assistance of third party utilities to extract your iPod Touch's content. See wjosten's procedure here:
    https://discussions.apple.com/docs/DOC-3141

  • A suggestion : use "loop array list" instead of ArrayList / LinkedList

    ArrayList is good at:
    get / set by index : O(1)
    appending : O(log(n))
    remove last : O(1)
    and very bad at:
    add middle : O(n)
    remove from middle : O(n)
    LinkedList is good at:
    fast remove from middle, if your iteraror already goes there : O(1)
    convenient methods : addFirst, addLast, removeFirst, removeLast : O(1)
    and very bad at :
    get / set by index : O(n)
    here I want to make a suggestion : use "loop array list" instead of the ArrayList and LinkedList.
    a "loop array list" is based on array, just like ArrayList. But it has 2 member-variables : the start position, and the real size. the start position can be anywhere within array.length. an element of index "i" is stored in array[ start + i ], and when (start + i > array.length), loop to the beginning of the array; when (start + i < 0), loop to the end of the array.
    this "loop array list" has all the good sides:
    get / set by index : O(1)
    add first / last : O(log(n))
    remove first / last : O(log(n))
    add / remove from middle : O(n)
    (note : because we shrink the backup-array when the real size is too small, add / remove operation take O(log(n)) now.)
    the only problem is : add / remove from middle. let's take a look at it.
    1. the LinkedList does NOT really add/remove from middle in O(1), you has to locate the element, which is O(n).
    2. O(n) is acceptable, O(n^2) is not acceptable. try this : keep removing first element from an very big ArrayList ( size>10^6 ) until it's empty.
    the fact is, any list can perform batch-remove / batch-add operation in O(n) instead of O(n^2). it's easy : allocate a new list, iterate the original list, copy the element into the new list if condition is satisfied.
    so, instead of "remove from middle", what we need is a new methods : removeAllByCondition( Condition condition ), and now the batch-remove operation can be done in O(n)
    here is an implementation of mine. I've tested it on my computer( 512mem + 2G cpu, win2k + jdk1.5 ), it's amazing, just a little slower then ArrayList when add last, and a liitle slower then LinkedList when batch-remove. in all other cases, it's far more better then those 2 kinds of List.
    // source code : List2
    import java.util.AbstractList;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.util.Collection;
    import java.util.Collections;
    import java.util.Comparator;
    import java.util.HashSet;
    import java.util.Iterator;
    import java.util.List;
    import java.util.NoSuchElementException;
    import java.util.Set;
    public final class List2<T> extends AbstractList<T> {
    private static int initialArrayLength = 4;
    private T[] array;
    private int start;
    private int size;
    private void init( T[] newArray, int start_a, int size_a ) {
    array = newArray;
    start = start_a;
    size = size_a;
    @SuppressWarnings("unchecked")
    private void init() {
    init( (T[]) new Object[ initialArrayLength ], 0, 0 );
    public List2() {
         init();
    @SuppressWarnings("unchecked")
    public List2( Collection<? extends T> collection ) {
         init(
              collection.toArray( (T[]) new Object[ collection.size() * 11 / 10 + 1 ] ),
              0,
              collection.size()
    private List2( T[] array_a, int start_a, int size_a ) {
         init( array_a, start_a, size_a );
    @SuppressWarnings("unchecked")
    public static <TT> List2<TT> createV( TT... elements ) {
         TT[] array = (TT[]) new Object[ elements.length * 11 / 10 + 1 ];
         System.arraycopy( elements, 0, array, 0, elements.length );
         return new List2<TT>( array, 0, elements.length );
    public static List2<Double> create( double... elements ) {
         Double[] array = new Double[ elements.length * 11 / 10 + 1 ];
         for( int i=0; i < elements.length; i++ )
              array[i] = elements;
         return new List2<Double>( array, 0, elements.length );
    public static List2<Integer> create( int... elements ) {
         Integer[] array2 = new Integer[ elements.length * 11 / 10 + 1 ];
         for( int i=0; i < elements.length; i++ )
              array2[i] = elements[i];
         return new List2<Integer>( array2, 0, elements.length );
    public static List2<Character> create( char... elements ) {
         Character[] array2 = new Character[ elements.length * 11 / 10 + 1 ];
         for( int i=0; i < elements.length; i++ )
              array2[i] = elements[i];
         return new List2<Character>( array2, 0, elements.length );
    public static List2<Character> create( String s ) {
         return create( s.toCharArray() );
    public List2<T> clone() {
         return new List2<T>( this );
    // basic
    public int size() {
         return size;
    private int index( int index ) {
         int i = start + index;
         if( i >= array.length )
              i -= array.length;
         return i;
    public T get( int d ) {
         if( d < 0 || d >= size )
              throw new IndexOutOfBoundsException();
         if( size == 0 )
              throw new NoSuchElementException();
         return array[ index( d ) ];
    public T set( int index, T element ) {
         if( index < 0 || index >= size )
              throw new IndexOutOfBoundsException();
         int i = index( index );
         T oldElement = array[i];
         array[i] = element;
         return oldElement;
    @SuppressWarnings("unchecked")
    private void copyAndSetToNewArray( int newArrayLength ) {
         T[] newArray = (T[]) new Object[ newArrayLength ];
         for( int i=0; i<size; i++ )
              newArray[i] = array[ index( i ) ];
         init( newArray, 0, size );
    public void addFirst( T element ) {
         if( size == array.length )
              copyAndSetToNewArray( size * 3 / 2 + 1 );
         int i = index( array.length - 1 );
         array[ i ] = element;
         start = i;
         size++;
    public void addLast( T element ) {
         if( size == array.length )
              copyAndSetToNewArray( size * 3 / 2 + 1 );
         array[ index( size ) ] = element;
         size++;
    public T removeFirst() {
         if( size == 0 )
              throw new NoSuchElementException();
         T oldElement = array[ start ];
         array[ start ] = null;
         start = index( 1 );
         size--;
         if( array.length > size * 2 + 1 )
              copyAndSetToNewArray( size * 11 / 10 + 1 );
         return oldElement;
    public T removeLast() {
         if( size == 0 )
              throw new NoSuchElementException();
         int i = index( size - 1 );
         T oldElement = array[i];
         array[i] = null;
         size--;
         if( array.length > size * 2 + 1 )
              copyAndSetToNewArray( size * 11 / 10 + 1 );
         return oldElement;
    @SuppressWarnings("unchecked")
    public int removeAll( ListCondition<T> condition ) {
         T[] newArray = (T[]) new Object[ array.length ];
         int iNew = 0;
         for( int i=0; i < size; i++ ) {
              T element = get( i );
              if( ! condition.isConditionSatisfied( this, i, element ) )
                   newArray[ iNew++ ] = element;
         int oldSize = size;
         init( newArray, 0, iNew );
         if( array.length > size * 2 + 1 )
              copyAndSetToNewArray( size * 11 / 10 + 1 );
         return size - oldSize;
    // aux
    public boolean equals(Object obj) {
         if( obj == this )
         return true;
         if( obj instanceof List2 ) {
              List2 that = (List2) obj;
              if( this.size != that.size )
                   return false;
              for( int i=0; i < size; i++ )
                   if( ! Tools.equals( this.array[ this.index(i) ], that.array[ that.index(i) ] ) )
                        return false;
              return true;
         if( obj instanceof List ) {
              List that = (List) obj;
              if( this.size != that.size() )
                   return false;
              Iterator thatIter = that.iterator();
              for( int i=0; i < size; i++ )
                   if( ! Tools.equals( this.array[ this.index(i) ], thatIter.next() ) )
                        return false;
              return true;
         return true;
    public int hashCode() {
         int hashCode = 1;
         for( int i=0; i < size; i++ ) {
              T element = array[ index( i ) ];
         hashCode = 31*hashCode + ( element==null ? 0 : element.hashCode() );
         return hashCode;
    public boolean isEmpty() {
         return size == 0;
    public T getFirst() {
         return get( 0 );
    public T getLast() {
         return get( size() - 1 );
    public T getRandom() {
         return get( (int) (Math.random() * size) );
    public int indexOf( Object element ) {
         for( int i=0; i < size; i++ )
              if( Tools.equals( array[ index( i ) ], element ) )
                   return i;
         return -1;
    public int lastIndexOf( Object element ) {
         for( int i=size-1; i >= 0; i-- )
              if( Tools.equals( array[ index( i ) ], element ) )
                   return i;
         return -1;
    public boolean contains( Object element ) {
         return indexOf( element ) != -1;
    public boolean add( T element ) {
         addLast( element );
         return true;
    @Deprecated
    public void add( int index, T element ) {
         throw new UnsupportedOperationException();
    public T remove() {
         return removeFirst();
    @Deprecated
    public boolean remove( Object element ) {
         throw new UnsupportedOperationException( "use removeAll( Condition ) instead" );
    @Deprecated
    public T remove( int index ) {
         throw new UnsupportedOperationException( "use removeAll( Condition ) instead" );
    public void clear() {
         init();
    public Object[] toArray() {
         Object[] result = new Object[ size ];
         for( int i=0; i < size; i++ )
         result[i] = array[ index( i ) ];
         return result;
    @SuppressWarnings("unchecked")
    public <TT> TT[] toArray( TT[] a ) {
    if( a.length < size )
    a = (TT[]) java.lang.reflect.Array.newInstance( a.getClass().getComponentType(), size );
    for( int i=0; i < size; i++ )
    a[i] = (TT) array[ index( i ) ];
    if( a.length > size )
         a[size] = null;
    return a;
    @SuppressWarnings("unchecked")
    public void sort() {
         Object[] a = toArray();
         Arrays.sort( a );
         for( int i=0; i < size; i++ )
              array[ i ] = (T) a[ i ];
         start = 0;
    @SuppressWarnings("unchecked")
    public void sortDesc() {
         Object[] a = toArray();
         Arrays.sort( a );
         for( int i=0, j=size-1; i < size; i++, j-- )
              array[ i ] = (T) a[ j ];
         start = 0;
    @SuppressWarnings("unchecked")
    public void sort( Comparator<T> comparator ) {
         T[] a = (T[]) toArray();
         Arrays.sort( a, comparator );
         for( int i=0; i < size; i++ )
              array[ i ] = a[ i ];
         start = 0;
    @SuppressWarnings("unchecked")
    public void sortDesc( Comparator<T> comparator ) {
         T[] a = (T[]) toArray();
         Arrays.sort( a, comparator );
         for( int i=0, j=size-1; i < size; i++, j-- )
              array[ i ] = a[ j ];
         start = 0;
    public String toString( String delimiter ) {
         return toString( "", delimiter, "", size() );
    public String toString( String prefix, String delimiter, String suffix, int max ) {
         StringBuffer stringBuffer = new StringBuffer( prefix );
         int dest = Math.min( max, size );
         for( int i=0; i < dest; i++ ) {
              stringBuffer.append( get(i) );
              if( i < dest - 1 )
                   stringBuffer.append( delimiter );
         if( size > max )
              stringBuffer.append( "...(" ).append( size() - max ).append( " more)" );
         stringBuffer.append( suffix );
         return stringBuffer.toString();
    // batch operation
    public boolean containsAll( Collection<?> that ) {
         Set<Object> thisSet = new HashSet<Object>( this );
         for( Object element : that )
              if( ! thisSet.contains( element ) )
                   return false;
         return true;
    @SuppressWarnings("unchecked")
    public List2<T> subList( int fromIndex, int toIndex ) {
         if( fromIndex < 0 || toIndex > size || toIndex < fromIndex )
              throw new IndexOutOfBoundsException();
         int newSize = toIndex - fromIndex;
         T[] newArray = (T[]) new Object[ newSize * 11 / 10 + 1 ];
         for( int i=fromIndex, iNew=0; i < toIndex; i++, iNew++ )
              newArray[ iNew ] = array[ index( i ) ];
         return new List2<T>( newArray, 0, newSize );
    public void addV( T... that ) {
         for( T element : that )
              addLast( element );
    public boolean addAll( Collection<? extends T> that ) {
         for( T element : that )
              addLast( element );
         return ! that.isEmpty();
    @Deprecated
    public boolean addAll( int index, Collection<? extends T> c ) {
         throw new UnsupportedOperationException();
    public void removeRest( T element ) {
         int position = lastIndexOf( element );
         if( position == -1 )
              return;
         while( ! Tools.equals( element, removeLast() ) );
    public void removeAllEquals( final T element ) {
         removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T currentElement) {
              return currentElement.equals( element );
    public void removeAllBetween( final T from, final T to ) {
         removeAll( new ListCondition<T>() {
              @SuppressWarnings("unchecked")
              public boolean isConditionSatisfied(List2 list, int index, T element) {
                   if( from != null && ((Comparable) from).compareTo( element ) > 0 )
                        return false;
                   if( to != null && ((Comparable) to).compareTo( element ) <= 0 )
                        return false;
                   return true;
    public boolean retainAll( Collection<?> that ) {
         final Set<Object> thatSet = new HashSet<Object>( that );
         int removeCount = removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T element) {
              return ! thatSet.contains( element );
         return removeCount > 0;
    public boolean removeAll( Collection<?> that ) {
         final Set<Object> thatSet = new HashSet<Object>( that );
         int removeCount = removeAll( new ListCondition<T>() { public boolean isConditionSatisfied(List2 list, int index, T element) {
              return thatSet.contains( element );
         return removeCount > 0;
    // unit test
    private static int maxTestCount = 1000 * 1000;
    public static void unitTest() throws Exception {
         // thest thoese methods for one time
         Tools.ensureEquals( new List2(), new ArrayList() );
         Tools.ensureNotEquals( List2.create( "abcde" ), new ArrayList() );
         Tools.ensureNotEquals( List2.create( "abcde" ), List2.create( "abcdef" ) );
         final List<Double> list1 = new ArrayList<Double>();
         final List2<Double> list2 = new List2<Double>();
         Runnable[] tasks = new Runnable[] {
              // test those methods that do NOT change the list
              new Runnable() { public void run() {
                   Tools.ensureEquals( new List2<Double>( list1 ), list1 );
                   Tools.ensureEquals( List2.createV( list1.toArray() ), list1 );
                   Tools.ensureEquals( List2.createV( list1.toArray( new Double[0] ) ), list1 );
                   double[] doubles = new double[ list1.size() ];
                   int i = 0;
                   for( double d : list1 )
                        doubles[i++] = d;
                   Tools.ensureEquals( List2.create( doubles ), list1 );
                   Tools.ensure( list1.isEmpty() == list2.isEmpty() );
                   Arrays.equals( list1.toArray(), list2.toArray() );
                   Tools.ensureEquals( list1, list2.clone() );
                   Double notExistElement = -2.0;
                   Tools.ensure( list1.indexOf( notExistElement ) == -1 );
                   Tools.ensure( list1.lastIndexOf( notExistElement ) == -1 );
                   Tools.ensure( list1.contains( notExistElement ) == false );
                   Tools.ensureEquals( list1.toString(), list2.toString() );
                   Tools.ensureEquals( list1.toString(), list2.toString() );
                   Tools.ensureEquals( list1.hashCode(), list2.hashCode() );
                   if( list1.isEmpty() )
                        return;
                   Tools.ensure( list1.get(0).equals( list2.getFirst() ) );
                   Tools.ensure( list1.get(list1.size()-1).equals( list2.getLast() ) );
                   Double existRandomElement = list2.getRandom();
                   Tools.ensure( list1.contains( existRandomElement ) );
                   Tools.ensure( list2.contains( existRandomElement ) );
                   Tools.ensure( list1.indexOf( existRandomElement ) == list2.indexOf( existRandomElement ) );
                   Tools.ensure( list1.indexOf( existRandomElement ) == list2.indexOf( existRandomElement ) );
                   int from = (int) (Math.random() * list1.size());
                   int to = (int) (Math.random() * (list1.size()+1));
                   if( from > to ) {
                        int t = from;
                        from = to;
                        to = t;
                   Tools.ensureEquals( list1.subList( from, to ), list2.subList( from, to ) );
              // test those methods that change the list
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   int i = (int) (Math.random() * list1.size());
                   double d = Math.random();
                   list1.set( i, d );
                   list2.set( i, d );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   int i = (int) (Math.random() * list1.size());
                   Tools.ensure( list1.get( i ).equals( list2.get( i ) ) );
              new Runnable() { public void run() {
                   double d = Math.random();
                   list1.add( 0, d );
                   list2.addFirst( d );
              new Runnable() { public void run() {
                   double d = Math.random();
                   list1.add( d );
                   list2.addLast( d );
              new Runnable() { public void run() {
                   double d = Math.random();
                   list1.add( d );
                   list2.addLast( d );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   Tools.ensure( list1.remove( 0 ).equals( list2.removeFirst() ) );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   Tools.ensure( list1.remove( list1.size() - 1 ).equals( list2.removeLast() ) );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   int i = 0;
                   for( Iterator<Double> iter=list1.iterator(); iter.hasNext(); i++ ) {
                        iter.next();
                        if( i % 3 == 0 )
                             iter.remove();
                   list2.removeAll( new ListCondition<Double>() { public boolean isConditionSatisfied(List2 list, int index, Double element) {
                        return index % 3 == 0;
              new Runnable() { public void run() {
                   double d = Math.random();
                   list1.add( d );
                   list2.add( d );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   Tools.ensure( list1.remove(0).equals( list2.remove() ) );
              new Runnable() { public void run() {
                   if( list1.isEmpty() )
                        return;
                   int r = (int) (Math.random() * list1.size());
                   Double element = list1.get( r );
                   int index = list1.lastIndexOf( element );
                   for( int i=list1.size()-1; i>=index; i-- )
                        list1.remove( i );
                   list2.removeRest( element );
              new Runnable() { public void run() {
                   list2.removeRest( Math.random() - 2 );
              new Runnable() { public void run() {
                   list1.clear();
                   list2.clear();
              new Runnable() { public void run() {
                   Collections.sort( list1 );
                   list2.sort();
              new Runnable() { public void run() {
                   Collections.sort( list1 );
                   Collections.reverse( list1 );
                   list2.sortDesc();
              new Runnable() { public void run() {
                   Comparator<Double> comparator = new Comparator<Double>() { public int compare(Double o1, Double o2) {
                        return o1.toString().substring(2).compareTo( o2.toString().substring(2) );
                   Collections.sort( list1, comparator );
                   list2.sort( comparator );
              new Runnable() { public void run() {
                   Comparator<Double> comparator = new Comparator<Double>() { public int compare(Double o1, Double o2) {
                        return o1.toString().substring(2).compareTo( o2.toString().substring(2) );
                   Collections.sort( list1, comparator );
                   Collections.reverse( list1 );
                   list2.sortDesc( comparator );
              new Runnable() { public void run() {
                   Double notExistElement = -2.0;
                   list2.removeAllEquals( notExistElement );
                   Tools.ensureEquals( list1, list2 );
                   list2.removeAllBetween( 0.5, 0.6 );
                   for( Iterator<Double> iter=list1.iterator(); iter.hasNext(); ) {
                        double d = iter.next();
                        if( d >= 0.5 && d < 0.6 )
                             iter.remove();
                   Tools.ensureEquals( list1, list2 );
         System.out.print( "test List2 " );
         for( int i=0; i < maxTestCount; i++ ) {
              tasks[ (int) (Math.random() * tasks.length) ].run();
              Tools.ensureEquals( list1, list2 );
              if( i % (maxTestCount/10) == 0 )
                   System.out.print( "." );
         System.out.println( " ok" );
    // source code : ListCondition
    public interface ListCondition<T> {
    boolean isConditionSatisfied( List2 list, int index, T element );

    Hi,
    I have the following statement:
    private List list = new ArrayList();
    why not use private ArrayList list = new
    ArrayList()?
    I know ArrayList implements List, so list has a wide
    scope, right? What's the benefit?
    Thanks,
    JieBy using the interface you are not tied to a specific implementation.
    Later, you may determine that using a LinkedList is more efficient to your specific code and then all you need to do is change the statement to:
    private List list = new LinkedList();As long as you are not casting the list reference to ArrayList (or something along those lines) you would not need to change anything else.

  • ArrayList - clear() or new ArrayList() ?

    Hi everybody,
    I have a loop which runs ~100-100000 times and in each looping an ArrayList is filled and holds elements ranging from 1 to 30000. I'm reusing the list and I'm wondering whether I should use clear() or better reinstantiate the List.
    I know that with StringBuffer the setLength(0) does not decrease the capacity of the StringBuffer, so that it might take much more memory than it actually needs.
    How about List?
    Does clear() decrease the capacity of the List?
    Would a reinstantiation be the better way?
    Or doesn't it matter anyway and a list with too much capacity is fine to use?
    Hope you can help
    Cheers
    bgcl

    Hi everybody,
    I have a loop which runs ~100-100000 times and in each
    looping an ArrayList is filled and holds elements
    ranging from 1 to 30000. I'm reusing the list and I'm
    wondering whether I should use clear() or better
    reinstantiate the List.
    I know that with StringBuffer the setLength(0) does
    not decrease the capacity of the StringBuffer, so that
    it might take much more memory than it actually
    needs.
    How about List?
    Does clear() decrease the capacity of the List?
    Would a reinstantiation be the better way?
    Or doesn't it matter anyway and a list with too much
    capacity is fine to use?
    Hope you can help
    Cheers
    bgclclear() will be better than new ArrayList() but the performance difference of clear() and new ArrayList(int) (with an int of an appropriate size) will be negligable.

  • List v = new Vector() how can i write this ?

    List v = new Vector() how can i write this ?
    vector does not 'extends' List rather it 'implements' only ......so how can write this way ? ( polymorphism applies only for 'extends' ).

    my question in a simple way is :
    List some_list extends Vector
    No, List is an interface; Vector is a concrete class. Read the javadocs.
    Vector implements List
    >
    AND
    List some_list implements Vector
    are these two same in behaviour
    our  apart from theoretical differences ?thanks
    Interfaces don't have any implementation; they're pure method signatures. When a concrete class implements an interface, it makes a promise that says "I will provide implementations for exactly these methods. Any client can call a method from the interface and I will do something 'sensible' if I'm written correctly."
    From the point of view of static and dynamic types, there's no difference between interfaces and classes.
    C++ has interfaces, too - they're classes with all pure virtual methods. If you understand how C++ works, the concept shouldn't be hard.
    ArrayList is preferred precisely because it isn't synchronized by default. (You can always make it so using java.util.Collections if you wish later on.) If you don't need synchronization, why pay the performance penalty?

  • How do I clear list of items purchased without deleting the apps?

    How do I clear list of items purchased without deleting the apps? Also, is there away to attach photos from camera roll when replying or writing a new email?

    There is no way to remove items from the purchased list on the iPad.
    You can send a photo from the mail app by tapping and holding down in the body of the email and select - Insert Photo or Video - from the black options bar that will pop up.

  • How do you return a List or a ArrayList?

    What's an example for returning both of the above? could someone provide examples??

    Chances are good that you'll not need to return a reference of the ArrayList type. Just return List. Example:
    public List method() {
        List list = new ArrayList();
        // do that voodoo...
        return list;
    }~

  • How can I move my contact list to new ID account and question about updating iOS

    How can I move my contact list to new ID account?
    And should I update my iOS system ?

    Hello Godde
    Lets start with checking out the articles below for setting up Family Sharing and more information about Apple ID’s. I will say that you will not be able to transfer any purchases to a different Apple ID, but you can rename the Apple ID. If you want to use Family Sharing, then you will need to just create a new iCloud account and then follow the steps in the second article to start sharing content between you to.
    Using your Apple ID for Apple services
    http://support.apple.com/kb/HT4895
    Sharing purchased content with Family Sharing
    http://support.apple.com/kb/HT201085
    Regards,
    -Norm G.

  • Is there a utility to list the new T Codes in ECC 6.0 compared with 4.7

    Hello:
    I am aware of  using SCMP and comparing the TSTC table for new Transactions.  Is there any OTHER utility provided ?
    Thanks

    Hi,
    You would need to perform the steps from 2a to 2d in transaction SU25.
    When you run these steps one by one, you will be getting the list of new and old transactions listed.
    You can adjust them accordingly.
    Regards,
    Imran

  • My old PC broke, it was the only pc my classic was sync with. New PC only shows 1 song (recent purchase) so am worried about sync to it in case I lose the list on my ipod which is still intacted. How can I transfer my list to new PC

    My old PC broke, it was the only pc my classic was sync with. New PC only shows 1 song (recent purchase) so am worried about syncing to new PC in case I lose the list on my iPod, which is still intacted. How can I transfer my list to new PC?

    I'm having a similar problem, but I do have the key and is not working anyway.
    My old pc was running on windows 7 and my new one is an apple running on Lion.
    My phone is an Iphone IV and I can see all the bookmarks there.
    In order to sync, what I did was click on the "I don't have the device with me", I entered the key that was provided and the process finish ok. It says congratulations, etc, etc.
    But the bookmarks are not there, I tried merging data and replacing data on this computer options but is the same.
    Any suggestions?

  • List of new tcodes in BI 7.0

    Hello All,
    we are planning to upgrade from BW3.5 to BI 7.0 , i want to know list of new tcodes which will be coming to BI envoirnment,
    please tell me know what all  are new tcodes, authorization objects,fields are coming to BI7.0 also i have run SU25 but i can not find RSECADMIN in any roles , please suggest where can i find all the new tcodes .
    Thanks
    DK

    Hi DK,
    please go through the links.
    Re: TCodes and Tables
    TCODE's in BI 7.0
    Authorization - BI 7.0
    Hope this helps u.
    Thanks,
    Sai Chand

  • How can I show the name in the list of new messages rather than the address

    I have noticed something weird in Apple mail. In the list of new messages, the FROM field sometimes shows the email address rather than the name of the sender (even if that sender is in my address book). Because of this, when I search for some users, I can search by name but for others I must search by email address. However, in the FROM field when I actually open the message, the full name is always in the field rather than the email address (if the contact is in my address book at least).
    Here's a screenshot that illustrates what I am talking about.
    http://img94.imageshack.us/img94/8126/applemail.jpg
    (notice that in the message list it says from [email protected] but in the message view below, it says from Tony XXXX
    My question is: Is there any way to display the actual name in the FROM field in the list of new messages rather than the email address, in the same way it is displayed when I actually open the message? I can't seem to find any settings that fix this.

    Yup, no longer an option.
    Leave feedback for Apple about the feature here:  www.apple.com/feedback

  • Where are MY ALERTS and weekly lists of new releases

    I regret downloading Itunes 9. I know how difficult it is to undo it. There are many things I don't like, but particularly I can't seem to access my alerts nor to be able to browse the weekly lists of new releases. Judging by all the complaints I hope Apple comes out with a new release SOON.

    My Alerts seems to be gone. You can comment on that here:
    http://www.apple.com/feedback/itunesapp.html
    The weekly new releases list is back; click on the Music tab at the top of any iTunes Store page and then look under the Quick Links at the right of the page for the Just Added link.

  • Copy one list items new list using client side object model

    Hi,
    I have a requirement like i need to copy one list information to new list with createdby and modified by fields.I need to use client side object model code.Can u please send me the code sample.
    Regards,
    Praveen

    Hi,
    According to your post, my understanding is that you want to copy one list items new list using client side object model.
    You can use console application.
    Here is a similar thread for your reference:
    https://social.technet.microsoft.com/Forums/sharepoint/en-US/28a43891-7505-4d34-b513-fdd66773c2a3/copy-list-item-to-another-list-using-client-object-model-in-console-application?forum=sharepointdevelopmentprevious
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Task List - Create New Form for Subtasks

    Hi, Is this possible to create a new form for SubTasks in SharePoint 2013 task List
    probably using Infopath. Out of Box, Sharepoint opens datasheet view to add the subtask for a main task. just want to know whether it is possible.
    Any help will be highly appreciated
    Ram Sharma

    Hi Ram,
    Per my understanding, you want to create a New Form for creating sub tasks.
    By default, the subtasks can only be created in the datasheet view, which means that there are some fields of a task cannot be filled in when subtask created, what’s
    more, there is no OOTB feature can meet this requirement.
    Actually, a subtask is also a normal task, the difference is that it can be connected with the parent task through a property “ParentID”. Let’s say if there is a task
    with “ID” 1, then the “ParentID” of its subtasks will be “1;#1”.
    Thus, as a workaround, you can create a custom New Form page with the extra “ParentID” field to be filled in. After submitting, a new task will be created, because
    the “ParentID” has a value which points to another task, this new task will be a subtask now. This can be done with Client Object Model programmatically.
    About how to work with Client Object Model:
    JavaScript Client Object Model
    http://msdn.microsoft.com/en-us/library/office/hh185006(v=office.14).aspx
    More information about JavaScript Client Object Model:
    How to: Create, Update, and Delete List Items Using JavaScript
    http://msdn.microsoft.com/en-us/library/office/hh185011(v=office.14).aspx  
    Common Programming Tasks in the JavaScript Object Model
    http://msdn.microsoft.com/en-us/library/office/hh185015(v=office.14).aspx
    Best regards
    Patrick Liang
    TechNet Community Support

Maybe you are looking for

  • SSD Upgraded MacBook Pro 2011 freezes, hangs, until SSD is no longer recognized

    Hello. Enough with the small talk. I have MacBook Pro 13" Late 2011 with Lion that I upgraded with a 128GB Vertex 4 SSD about 8 months ago. I moved the original HDD into the optical bay and slipped the Vertex 4 into its place. Everything was all good

  • HP PHOTOSMART 5524 SERIES PRINTER WILL NOT CONNECT WIRELESSLY​/COMMUNICA​TE WITH LAPTOP. PLEASE HELP.

    I am really hoping that someone can help me resolve a serious issue with a new printer. I have tried every diagnostic tool including the HP print & scan doctor and my printer still doesn't seem to connect to my laptop or print.  Although it does prin

  • NTSC to PAL yields 1 FPS?

    I'm not sure what's going on here, but I have a project where I need to convert 29.97 Fps AVI video compressed with XVID over to PAL DV AVIs... However, when I set ouput to DV PAL, the output only appears to be rendering something like 1 fps... This

  • Internet explorer 11 not working in app mode

    Hi, I have a Lenovo desktop computer with Windows 8.1. IE 11 worked perfectly well in both app and desktop modes but since 2-3 weeks my IE doesn't open in app mode. I think it might be linked to the update following the IE security problem. I tried t

  • Vista - Connected with Limited Access???

    Please help!!! This problem is driving me mad. Every time I try to connect to the router whilst wireless it says "Connected with Limited Access"? I then plug the cable back in and "ta dah" it works fine. I have tried almost everything and cannot unde