How iterate over nested list (any depth)? I have the following structure
Com 1
Com 2
Com 55
Com 551
Com 552
Com 56
Com 57
Com 66
Com 67
Com 99
Com 3
Com 33
Com 34
Com 35
Com 4
Com 41
Com 42
Com 421
Com 423
I want export data to txt file with hiearchy. How detect when should I add "space" to make hierarchy?
@Entity
public class Company {
private Long id;
private String name;
private List<Company> children = new ArrayList<>();
public Company() {
}
//getters and setters
public Stream<Company> flattened() {
return Stream.concat(
Stream.of(this),
children.stream().flatMap(Company::flattened));
}
}