Java String Indent Format indent(int level)

Here you can find the source of indent(int level)

Description

Return a string that generates an indentation string (a sequence of spaces) for the given indentation level.

License

Open Source License

Parameter

Parameter Description
level The indentation level.

Return

The indentation string that corresponds to the given indentation level.

Declaration

public static String indent(int level) 

Method Source Code

//package com.java2s;
/* This class provides basic utilities used across a variety of classes.
    /*ww w  . jav a2s.c o  m*/
 Copyright (c) 2002-2005 The University of Maryland.
 All rights reserved.
 Permission is hereby granted, without written agreement and without
 license or royalty fees, to use, copy, modify, and distribute this
 software and its documentation for any purpose, provided that the above
 copyright notice and the following two paragraphs appear in all copies
 of this software.
    
 IN NO EVENT SHALL THE UNIVERSITY OF MARYLAND BE LIABLE TO ANY PARTY
 FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
 ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF
 THE UNIVERSITY OF MARYLAND HAS BEEN ADVISED OF THE POSSIBILITY OF
 SUCH DAMAGE.
    
 THE UNIVERSITY OF MARYLAND SPECIFICALLY DISCLAIMS ANY WARRANTIES,
 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE
 PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF
 MARYLAND HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
 ENHANCEMENTS, OR MODIFICATIONS.
    
 */

public class Main {
    /**
     * Return a string that generates an indentation string (a sequence of
     * spaces) for the given indentation level. Each indentation level unit is
     * four characters wide.
     * 
     * @param level
     *            The indentation level.
     * @return The indentation string that corresponds to the given indentation
     *         level.
     */
    public static String indent(int level) {
        StringBuffer indent = new StringBuffer();
        int i;

        for (i = 0; i < level; i++) {
            indent.append("    ");
        }

        return indent.toString();
    }
}

Related

  1. indent(int indent)
  2. indent(int indent, int tab, String string)
  3. indent(int indent, StringBuffer sb)
  4. indent(int indentLevel)
  5. indent(int level)
  6. indent(int level)
  7. indent(int level)
  8. indent(int n)
  9. indent(int nb)