KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > help > internal > util > StringUtil


1 /*******************************************************************************
2  * Copyright (c) 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.help.internal.util;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.List JavaDoc;
15 import java.util.StringTokenizer JavaDoc;
16
17 public class StringUtil {
18
19     /*
20      * Helper method for String#split to handle the case where we
21      * might be running on Foundation class libraries instead of 1.4.
22      */

23     public static String JavaDoc[] split(String JavaDoc string, String JavaDoc delimiters) {
24         try {
25             return string.split(delimiters);
26         } catch (NoSuchMethodError JavaDoc e) {
27             // not running 1.4 so try a string tokenizer
28
List JavaDoc result = new ArrayList JavaDoc();
29             for (StringTokenizer JavaDoc tokenizer = new StringTokenizer JavaDoc(string, delimiters); tokenizer.hasMoreTokens(); )
30                 result.add(tokenizer.nextToken());
31             return (String JavaDoc[]) result.toArray(new String JavaDoc[result.size()]);
32         }
33     }
34 }
35
Popular Tags