code: public void replaceMenuById(SubMenuItem subMenu, MenuItem toReplace) {
          synchronized (subMenuItems) {
              ArrayList<MenuItem> list = subMenuItems.get(subMenu);
              int idx = -1;
              for (int i = 0; i < list.size(); ++i) {
                  if (list.get(i).getId() == toReplace.getId()) {
                      idx = i;
                  }
              }
  
              if (idx != -1) {
                  MenuItem oldItem = list.set(idx, toReplace);
                  if (toReplace.hasChildren()) {
                      ArrayList<MenuItem> items = subMenuItems.remove(oldItem);
                      subMenuItems.put(toReplace, items);
                  }
              }
  
          }
      }
docs: Replace the menu item that has a given parent with the one provided
  @param subMenu the parent
  @param toReplace the menu item to replace by ID