I have a list in which I need to add a prefix to all elements of my list.
The following is the way I accomplish this by iterating over a list and then adding it. Is there any other better way to do this? Any one or two liners that can do the same things?
private static final List<DataType> DATA_TYPE = getTypes(); public static LinkedList<String> getData(TypeFlow flow) { LinkedList<String> paths = new LinkedList<String>(); for (DataType current : DATA_TYPE) { paths.add(flow.value() + current.value()); } return paths; }
I need to return a LinkedList, as I use some methods of the LinkedList class, such as removeFirst .
I'm on Java 7 now.
source share