
{filelink=23}
/**
* @(#)ExempleSplit.java
* Découper une chaîne de caractères(String) à l'aide d'un séparateur
*
* @author sakoba(mesexemples.com)
*sakoba(java.mesexemples.com) @version 1.00 2012/12/4
*/
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
public class ExempleSplit {
public static void main (String[] args)
{
String str = "Tu es cool";
String str2 = "Foot, Ballon,Sport";
// Découper les String en deux tokens
String[] array1 = StringUtils.split( str, " ,", 2 );
String[] array2 = StringUtils.split( str2, " ,", 2 );
System.out.println( ArrayUtils.toString( array1 ) ); // {Tu,es cool}
System.out.println( ArrayUtils.toString( array2 ) ); // {Foot,Ballon,Sport}
}
}