If I understand you correctly, then you want to create a List<Car> that gets the color from one list and the model from the other. To do this, just create new Cars and add them to a new List:
List<Car> newlist = new ArrayList<Car>();
for( int i = 0; i < list1.size() && i < list2.size(); ++i )
newlist.Add( new Car( list1.get(i).getColor(), list2.get(i).getModel() ) );
However if you do not know which list contains null for each car, you would have to do some checks:
for( int i = 0; i < list1.size() && i < list2.size(); ++i )
{
String color = list1.get(i).getColor();
if( color == null )
color = list2.get(i).getColor();
String model = list1.get(i).getModel();
if( model == null )
model = list2.get(i).getModel();
newlist.Add( new Car( color, model ) );
}
Note: I assumed Car has a common interface, ie:
class Car
{
public String getModel(){ return model; }
public String getColor(){ return color; }
public Car( String c, String m )
{
color = c;
model = m;
}
}
Car.Carobjects with 2 strings in there. Where are the lists?nulls in the first place?