Here you can find the source of expandTabs(String inputString, int numberOfSpaces)
public static String expandTabs(String inputString, int numberOfSpaces)
//package com.java2s; //License from project: Open Source License public class Main { public static String expandTabs(String inputString, int numberOfSpaces) { if (inputString.indexOf('\t') == -1) return inputString; int inputStringLength = inputString.length(); StringBuffer buffer = new StringBuffer(inputStringLength); String spaces = nCopies(numberOfSpaces, ' '); for (int i = 0; i < inputStringLength; i++) { char c = inputString.charAt(i); if (c == '\t') buffer.append(spaces);/* w w w. j av a 2 s.com*/ else buffer.append(c); } return buffer.toString(); } public static String nCopies(int copyCount, char charToCopy) { StringBuffer buffer = new StringBuffer(copyCount); for (int i = 0; i < copyCount; i++) buffer.append(charToCopy); return buffer.toString(); } }