Java tutorial
//package com.java2s; import java.util.StringTokenizer; public class Main { private static String getLastInPathElement(String path) { // StringTokenizer st = new StringTokenizer(path,"."); // int cpt = st.countTokens(); //// if (cpt==1) //// return root; // int i = cpt-1; // for (int j = 0; j < i; j++) { // st.nextToken(); // } return getElementInPathAtPosixFromEnd(path, 1); } private static String getElementInPathAtPosixFromEnd(String path, int posix) { StringTokenizer st = new StringTokenizer(path, "."); int cpt = st.countTokens(); // if (cpt==1) // return root; int i = cpt - posix; for (int j = 0; j < i; j++) { st.nextToken(); } return (String) st.nextToken(); } }