Java String Split splitIntoPairs(String subDirName)

Here you can find the source of splitIntoPairs(String subDirName)

Description

splits the given subDirName into pairs of characters (odd length results in exception)

License

Open Source License

Declaration

private static List<String> splitIntoPairs(String subDirName) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/* w  w w.  ja v  a  2  s.  c o  m*/
     * splits the given subDirName into pairs of characters (odd length results in exception)
     */
    private static List<String> splitIntoPairs(String subDirName) {
        if (subDirName.length() % 2 == 1) {
            throw new IllegalArgumentException("subDirName contains an odd number of characters");
        } else {
            List<String> ret = new ArrayList<>();
            int i = 0;
            while (i < subDirName.length()) {
                ret.add(subDirName.substring(i, i + 2));
                i = i + 2;
            }
            return ret;
        }
    }
}

Related

  1. splitInput(String cliInput)
  2. splitIntArray(final String iInput)
  3. splitIntegerFromString(String str)
  4. splitIntegerPerDigit(int i)
  5. splitIntoPackages(String stmt)
  6. splitInts(String str)
  7. splitJsonObjects(String string)
  8. splitJsonObjects(String value)
  9. splitLargeStringIfNecessary(String s)