Here you can find the source of shiftLastAlphabets(String id)
Parameter | Description |
---|---|
id | id |
public static String shiftLastAlphabets(String id)
//package com.java2s; //License from project: Apache License public class Main { /**// ww w .jav a2 s . c o m * shift last character. * * @param id id * @return value after shift. */ public static String shiftLastAlphabets(String id) { if (id == null || "".equals(id) || id.length() <= 1) return id; int firstNumberPosition = 0; int lastNumberPosition = id.length() - 1; while (firstNumberPosition < id.length() && Character.isLetter(id.charAt(firstNumberPosition))) firstNumberPosition++; while (lastNumberPosition >= 0 && Character.isLetter(id.charAt(lastNumberPosition))) lastNumberPosition--; if (firstNumberPosition > lastNumberPosition) return id; StringBuffer sb = new StringBuffer(); sb.append(id.substring(0, firstNumberPosition)); sb.append(id.substring(lastNumberPosition + 1, id.length())); sb.append(id.substring(firstNumberPosition, lastNumberPosition + 1)); return sb.toString(); } }