Here you can find the source of stripLastElement(String str)
public static String stripLastElement(String str)
//package com.java2s; /**//from w ww. j ava 2 s .c o m * Copyright 2001-2014 CryptoHeaven Corp. All Rights Reserved. * * This software is the confidential and proprietary information * of CryptoHeaven Corp. ("Confidential Information"). You * shall not disclose such Confidential Information and shall use * it only in accordance with the terms of the license agreement * you entered into with CryptoHeaven Corp. */ import java.util.*; public class Main { public static String stripLastElement(String str) { String last = getLastElement(str); if (last.length() > 0) { int index = str.lastIndexOf(last); if (index >= 0) { if (index == 0) str = ""; else str = str.substring(0, index); str = str.trim(); while (str.endsWith(",") || str.endsWith(";")) { str = str.substring(0, str.length() - 1).trim(); } } } return str; } public static String getLastElement(String str) { String lastToken = ""; str = str.trim(); if (str.endsWith(",") || str.endsWith(";")) lastToken = ""; else { StringTokenizer st = new StringTokenizer(str, ",;"); lastToken = str; while (st.hasMoreTokens()) lastToken = st.nextToken().trim(); } return lastToken; } }