Here you can find the source of substringBeforeLast(String text, String separator)
public static String substringBeforeLast(String text, String separator)
//package com.java2s; public class Main { private static final int INDEX_NOT_FOUND = -1; public static String substringBeforeLast(String text, String separator) { int index = lastIndexOf(text, separator); return substringBefore(text, index); }/* w w w. j a va 2s .co m*/ private static int lastIndexOf(String text, String separator) { if (isBlank(text)) { return INDEX_NOT_FOUND; } return text.lastIndexOf(separator); } public static String substringBefore(String text, String separator) { int index = indexOf(text, separator); return substringBefore(text, index); } private static String substringBefore(String text, int index) { if (index == INDEX_NOT_FOUND) { return text; } return text.substring(0, index); } public static boolean isBlank(String text) { return text == null || text.trim().isEmpty(); } private static int indexOf(String text, String separator) { if (isBlank(text)) { return INDEX_NOT_FOUND; } return text.indexOf(separator); } }