I have started working with Java 8 and trying to convert some loops and old syntax in my code to lambdas and streams.
So for example, I'm trying to convert this while and for loop to stream, but I'm not getting it right:
List<String> list = new ArrayList<>();
if (!oldList.isEmpty()) {// old is a List<String>
Iterator<String> itr = oldList.iterator();
while (itr.hasNext()) {
String line = (String) itr.next();
for (Map.Entry<String, String> entry : map.entrySet()) {
if (line.startsWith(entry.getKey())) {
String newline = line.replace(entry.getKey(),entry.getValue());
list.add(newline);
}
}
}
}
I wanted to know if it's possible to convert the above example to a single stream where there is a while loop inside of a for loop.