Java String Join joinSplit(String record, String regex)

Here you can find the source of joinSplit(String record, String regex)

Description

join Split

License

Open Source License

Parameter

Parameter Description
record a parameter
regex a parameter

Declaration

public static String[] joinSplit(String record, String regex) 

Method Source Code

//package com.java2s;
/**/*from  w  w  w . j a va  2  s  .  c  o  m*/
 *   22/dic/2010
 *
 * Copyright (c) 2010 Alten Italia, All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * Alten Italia ("Confidential Information").
 * You shall not disclose such Confidential Information and shall use it
 * only in accordance with the terms of the license agreement you entered 
 * into with Alten Italia.
 *
 * Alten Italia - MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY 
 * OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO 
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, 
 * OR NON-INFRINGEMENT. ALTEN ITALIA SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED
 * BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR 
 * ITS DERIVATIVES.
 */

import java.util.ArrayList;
import java.util.Collection;

public class Main {
    /**
     * @param record
     * @param regex
     * @return
     */
    public static String[] joinSplit(String record, String regex) {
        String[] split = record.split(regex);

        Collection<String> elements = new ArrayList<String>();

        for (int i = 1; i < split.length; i++) {
            regex = (regex.indexOf("|") != -1) ? regex.substring(0, regex.indexOf("|")) : regex;
            elements.add(regex + split[i]);
        }
        return elements.toArray(new String[0]);
    }
}

Related

  1. joinMap(String keyValueSeperator, String recordSeperator, Map map)
  2. JoinMaps(Map into, Map other)
  3. joinPath(String part1, String part2)
  4. joinPaths(String... paths)
  5. joinRepeat(int size, String s, String delim)
  6. joinString(String separator, String... elements)
  7. joinValues(Map map, String separator)
  8. joinWithSeparation(String a, String separator, String b)
  9. merge(ArrayList pArrayList, String pJoin)