Perhaps something like this will serve as a starting point for you.
List<D> objectsEmpty = new ArrayList<>(); List<D> objectslist = new ArrayList<>(); String dat = "1,Tom:2,Jack:3,Willy:4,Sam"; void init() { String data[] = dat.split( ":" ); for( int i = 0; i < data.length; i ++ ) { objectslist.add( createObject( Integer.parseInt( data[ i ].split( "," )[ 0 ] ), data[ i ].split( "," )[ 1 ] ) ); } deleteObject( objectslist.remove( 2 ) ); objectslist.add( createObject( 12, "Hardy" ) ); for( int i = 0; i < objectslist.size(); i ++ ) { System.out.println( objectslist.get( i ).getName() ); } } void deleteObject( D obj ) { obj.setName( "" ); obj.setValue( 0 ); objectsEmpty.add( obj ); } D createObject( int value, String name ) { D newObject; if( objectsEmpty.isEmpty() ) { newObject = new D( value, name ); objectslist.add( newObject ); return newObject; } // modification suggested by k314159. newObject = objectsEmpty.remove( 0objectsEmpty.size() - 1 ); newObject.setName( name ); newObject.setValue( value ); return newObject; } class D { int value = 0; String name = ""; public D( int v, String n ) { value = v; name = n; } public int getValue() { return value; } public void setValue( int value ) { this.value = value; } public String getName() { return name; } public void setName( String name ) { this.name = name; } }