Here you can find the source of expandTabs(String text, int tabSize)
public static String expandTabs(String text, int tabSize)
//package com.java2s; //License from project: Open Source License public class Main { public static String expandTabs(String text, int tabSize) { String rv = ""; if (text != null) { if (text.indexOf('\t') >= 0) { StringBuilder buf = new StringBuilder(); int len = text.length(); for (int i = 0; i < len; i++) { char ch = text.charAt(i); if (ch == '\t') { int n = tabSize - (buf.length() % tabSize); for (int k = 0; k < n; k++) { buf.append((char) '\u0020'); }/*from ww w . j av a2 s. co m*/ } else { buf.append(ch); } } rv = buf.toString(); } else { rv = text; } } return rv; } }