What I'm trying to achieve is probably quite pointless but I would like to find this out to satisfy my curiosity.
I'm trying to create a single efficient statement that would create a new list based on another and add a new value to the end.
I'm new to lambda expressions and I'm not sure what kind of list should I be using for this.
the method would look something like this:
private List<Integer> conjoin(List<Integer> list, Integer newValue){
return new ArrayList<Integer>(list).stream()
.map(value -> list.indexOf(value)==(list.size()-1) ?
Arrays.asList(value, newValue) :
Arrays.asList(value))
.flatMap(Collection::stream)
.collect(Collectors.toList());
}
but more neat and efficient.
Or is there a built-in method doing the same that I didn't know about?