I have this UI object with below structure, i dont have control on how that list is populated, but i had to remove some child items meeting my condition, can anyone please suggest how i can do it (Language is Java)
Class definition
Class MenuItemObj {
          private string menuID
          private string menuType
          private string menuDescription
          private MenuItemObj[] children
}
so my finaly menu item will be in array, menuItemObj[], and each menuItemObj will look like this (not exact code)
MenuItemObj menuID menuDescription children --> have to remove child from here based on condition MenuItemObj children MenuItemObj[] --> have to remove child from here based on condition
     MenuItemObj
condition i have is, menuId and type, any idea how can i remove those child objects?
i tried below logic, but its getting removed from current list, but not in the final list
public static MenuItemObj[] removeChildMenu(MenuItemObj[] menuItemArr) {
     List newMenuItemList = menuItems.toList()
     for( aMenuitem : menuItemArr) {
        if(aMenuItem.Children != null) {
            removeChildMenu(aMenuitem.children)
        } else {
                 newMenuItemList.removeif(conditionToRemove)
   
 }    
 return newMenuItemList.toArray()
}
There is no error or anything but way I handle the array and list in this recursive calls seems not going as I intended. Any suggestions on this please.