omerhakanbilici omerhakanbilici - 1 year ago 95
Java Question

Fill list with another object list

Is there any convenient way to move/copy id's from


With java 8 streams maybe?

public class SomeObject() {
private Long id;
private String value;

public Long getId() { return id; }
public void setId(Long id) { = id; }
public String getValue() { return value; }
public void setValue(String value) { this.value = value; }

Somewhere in code:

public void doSomething() {

List<SomeObject> objList = fillWithManyObjects(); //getting objects with values
List<Long> idList = new ArrayList<Long>();

objList.forEach(obj -> flightSlotIdSet.add(obj.getId));


Answer Source

Its a simple stream

 List<Long> idList =
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download