get Tab Indexes - Java java.lang

Java examples for java.lang:String Index

Description

get Tab Indexes

Demo Code

//package com.java2s;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] argv) {
        String text = "java2s.com";
        System.out.println(getTabIndexes(text));
    }//w  ww . j a  va 2  s . com

    /**
     * 
     */
    public static List<Integer> getTabIndexes(String text) {
        List<Integer> tabIndexes = null;

        if (text != null) {
            int index = text.indexOf('\t');
            // returning null if no tabs
            if (index >= 0) {
                tabIndexes = new ArrayList<Integer>();
                do {
                    tabIndexes.add(index);
                    index = text.indexOf('\t', index + 1);
                } while (index >= 0);
            }
        }

        return tabIndexes;
    }
}

Related Tutorials