Here you can find the source of lastIndexOf(char[] toBeFound, char[] array)
public static final int lastIndexOf(char[] toBeFound, char[] array)
//package com.java2s; /******************************************************************************* * Copyright (c) 2004, 2016 IBM Corporation and others. * 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://from w w w . jav a 2 s . c o m * IBM Corporation - initial API and implementation * Andrew Ferguson (Symbian) * Markus Schorn (Wind River Systems) * Sergey Prigogin (Google) *******************************************************************************/ public class Main { public static final int lastIndexOf(char[] toBeFound, char[] array) { return lastIndexOf(toBeFound, array, 0); } /** * @since 5.11 */ public static int lastIndexOf(char toBeFound, char[] array) { return lastIndexOf(toBeFound, array, 0); } /** * @since 5.11 */ public static int lastIndexOf(char toBeFound, char[] array, int fromIndex) { for (int i = array.length; --i >= fromIndex;) { if (array[i] == toBeFound) { return i; } } return -1; } /** * @since 5.11 */ public static int lastIndexOf(char[] toBeFound, char[] array, int fromIndex) { int i = array.length; int j = toBeFound.length; while (true) { if (--j < 0) return i; if (--i < fromIndex) return -1; if (toBeFound[j] != array[i]) { i += toBeFound.length - j - 1; j = toBeFound.length; } } } }