public static Rectangle[] computeDifference(final Rectangle rect1, final Rectangle rect2) { if (rect1 == null || rect1.isEmpty() || rect2 == null || rect2.isEmpty()) { return new Rectangle[0]; } Rectangle isection = rect1.intersection(rect2); if (isection.isEmpty()) { return new Rectangle[0]; } ArrayList reminders = new ArrayList(4); substract(rect1, isection, reminders); return (Rectangle[]) reminders.toArray(new Rectangle[0]); }