Here you can find the source of intersects(int start1, int length1, int start2, int length2)
public static boolean intersects(int start1, int length1, int start2, int length2)
//package com.java2s; /******************************************************************************* * Copyright (c) 2014,2015 Hideki Yatomi * All rights reserved. This program and the accompanying materials are made * available under the terms of the Eclipse Public License v1.0 which * accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html ******************************************************************************/ public class Main { public static boolean intersects(int start1, int length1, int start2, int length2) { if (length1 == 0) length1 = 1;/*from ww w .j a v a 2 s . c o m*/ if (length2 == 0) length2 = 1; int min1 = Math.min(start1, start1 + length1); int max1 = Math.max(start1, start1 + length1); int min2 = Math.min(start2, start2 + length2); int max2 = Math.max(start2, start2 + length2); return (min1 < max2) && (min2 < max1); } }