Here you can find the source of splitOnEntireString(String target, String delimiter)
Parameter | Description |
---|---|
target | The text to break up. |
delimiter | The sub-string which is used to break the target. |
public static List splitOnEntireString(String target, String delimiter)
//package com.java2s; /*/*from w w w .j a v a 2 s . c o m*/ * JBoss, Home of Professional Open Source. * * See the LEGAL.txt file distributed with this work for information regarding copyright ownership and licensing. * * See the AUTHORS.txt file distributed with this work for a full listing of individual contributors. */ import java.util.ArrayList; import java.util.List; public class Main { /** * Break a string into pieces based on matching the full delimiter string in the text. The delimiter is not included in the * returned strings. * * @param target The text to break up. * @param delimiter The sub-string which is used to break the target. * @return List of String from the target. */ public static List splitOnEntireString(String target, String delimiter) { ArrayList result = new ArrayList(); if (delimiter.length() > 0) { int index = 0; int indexOfNextMatch = target.indexOf(delimiter); while (indexOfNextMatch > -1) { result.add(target.substring(index, indexOfNextMatch)); index = indexOfNextMatch + delimiter.length(); indexOfNextMatch = target.indexOf(delimiter, index); } if (index <= target.length()) { result.add(target.substring(index)); } } else { result.add(target); } return result; } }