All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.naviit.libs.common.util.StringSplitter Maven / Gradle / Ivy

There is a newer version: 1.0.3
Show newest version
/************************************************
 * Copyright 2017 by DTT - All rights reserved. *    
 ************************************************/
package com.github.naviit.libs.common.util;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author  Dang Thanh Tung 
 * {@literal }
 * @since   28/12/2017
 */
public class StringSplitter {
  
  public static List splitBySpace(String value) {
    if (StringUtil.isEmpty(value)) {
      return new ArrayList();
    }
    String[] lstChar = value.split(StringUtil.SPACE);
    return Arrays.asList(lstChar);
  }

  public static List toListBySpace(String value) {
    if (value == null) return new ArrayList(0);
    List temp = new ArrayList((value.length() / 2) + 1);
    int start = 0;
    int i = 1;
    while (i < value.length()) {
      char c = value.charAt(i);
      if (Character.isWhitespace(c) || Character.isSpaceChar(c)) {
        String element = value.substring(start, i);
        if (!element.isEmpty()) temp.add(element);
        start = i + 1;
        i++;
        continue;
      }
      i++;
    }
    if (start < value.length()) {
      String element = value.substring(start);
      if (!element.isEmpty()) temp.add(element);
    }
    return temp;
  }

  public static String[] toArrayBySpace(String value){  
    List list = toListBySpace(value);
    return list.toArray(new String[list.size()]);
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy