Java tutorial
//package com.java2s; /** * Copyright (c) 2013, 2014 Denis Nikiforov. * 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 * * Contributors: * Denis Nikiforov - initial API and implementation */ public class Main { /** * Returns the part of 'tail' that is not present at the end of 'text'. For * example if text = 'abc' and tail = 'cd' this method returns 'd'. If 'tail' can * not be found at the end of 'text', 'tail' is returned as is. */ public static String getMissingTail(String text, String tail) { for (int i = 1; i < tail.length(); i++) { int endIndex = text.length(); int end = Math.max(0, endIndex); int start = Math.max(0, end - i); String contentTail = text.substring(start, end); String proposalHead = tail.substring(0, i); if (contentTail.equals(proposalHead)) { return tail.substring(i); } } return tail; } }