Java Bit Shift shiftLastAlphabets(String id)

Here you can find the source of shiftLastAlphabets(String id)

Description

shift last character.

License

Apache License

Parameter

Parameter Description
id id

Return

value after shift.

Declaration

public static String shiftLastAlphabets(String id) 

Method Source Code

//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();
    }
}

Related

  1. shiftCharacter(char c, int offset)
  2. shiftDouble(Object o, double shift, String suffix)
  3. shiftHorizontally(int inkX, int inkXWidth, int textWidth)
  4. shiftIdentifier(StringBuffer buffer, int posBegin, int posEnd)
  5. shiftKeyword(StringBuffer buffer, int posBegin, int posEnd, String keyword, boolean ignoreCase, boolean wholeWord)
  6. shiftLeft(char ch)
  7. shiftLeft(final Character orig, final int shiftDistance)
  8. shiftPath(String uri)
  9. shiftsForNextPowerOfTwo(final int targetSize)