Knowledge Walls
John Peter
Pune, Maharashtra, India
Custom Left and Right Method of String manipulation in Java Example
public class CustomLeftRightMethodExample {
    public static String left(String data,int no_of_chars){
        if (data.length() > no_of_chars)
            return data.substring(0, no_of_chars);
            return data;
    public static String right(String data,int no_of_chars){
        if (data.length() > no_of_chars)
            return data.substring(data.length()-no_of_chars, data.length());
            return data;
    public static void main(String args[]) throws Exception{    
String Class substring method is used to parse the string using staring index and end index.

substring(starting index,ending index)

Left: left string has to specify 0 as starting index. and number of characters should be ending index.
Right: right string has to specify (length - number of characters) as starting index and number of characters is the ending index.
Next Topics
Next lessons of current book.
Computer software engineer articles of One day One Thing to Know
Best Lessons of "One day One Thing to Know"
Top lessons which are viewed more times.
  Copyright © 2014 Knowledge walls, All rights reserved
keep your tutorials and learnings with KnowledgeWalls. Don't lose your learnings hereafter. Save and revise it whenever required.
Click here for more details