Java examples for java.lang:String Index
get Last Non Space Index
//package com.java2s; public class Main { public static void main(String[] argv) { CharSequence val = "java2s.com"; System.out.println(getLastNonSpaceInd(val)); }/*from www . j av a 2 s . c o m*/ public static int getLastNonSpaceInd(CharSequence val, int startInd) { int res = startInd; while (0 <= res) { char c = val.charAt(res); if (!Character.isSpaceChar(c) && !Character.isWhitespace(c)) break; --res; } return res; } public static int getLastNonSpaceInd(CharSequence val) { return getLastNonSpaceInd(val, val.length() - 1); } }