Here you can find the source of splitIntArray(final String iInput)
public static int[] splitIntArray(final String iInput)
//package com.java2s; /*/*from w ww . ja va 2 s. com*/ * * * Copyright 2014 Orient Technologies LTD (info(at)orientechnologies.com) * * * * Licensed under the Apache License, Version 2.0 (the "License"); * * you may not use this file except in compliance with the License. * * You may obtain a copy of the License at * * * * http://www.apache.org/licenses/LICENSE-2.0 * * * * Unless required by applicable law or agreed to in writing, software * * distributed under the License is distributed on an "AS IS" BASIS, * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * * See the License for the specific language governing permissions and * * limitations under the License. * * * * For more information: http://www.orientechnologies.com * */ import java.util.ArrayList; import java.util.Collection; import java.util.List; public class Main { public static final char RECORD_SEPARATOR = ','; public static int[] splitIntArray(final String iInput) { final List<String> items = split(iInput, RECORD_SEPARATOR); final int[] values = new int[items.size()]; for (int i = 0; i < items.size(); ++i) { values[i] = Integer.parseInt(items.get(i).trim()); } return values; } public static List<String> split(final String iSource, final char iRecordSeparator, final char... iJumpCharacters) { return split(iSource, 0, iSource.length(), iRecordSeparator, iJumpCharacters); } public static Collection<String> split(final Collection<String> iParts, final String iSource, final char iRecordSeparator, final char... iJumpCharacters) { return split(iParts, iSource, 0, iSource.length(), iRecordSeparator, iJumpCharacters); } public static List<String> split(final String iSource, final int iStartPosition, final int iEndPosition, final char iRecordSeparator, final char... iJumpCharacters) { return (List<String>) split(new ArrayList<String>(), iSource, iStartPosition, iSource.length(), iRecordSeparator, iJumpCharacters); } public static Collection<String> split(final Collection<String> iParts, final String iSource, final int iStartPosition, final int iEndPosition, final char iRecordSeparator, final char... iJumpCharacters) { return split(iParts, iSource, iStartPosition, iEndPosition, String.valueOf(iRecordSeparator), iJumpCharacters); } public static Collection<String> split(final Collection<String> iParts, final String iSource, final int iStartPosition, int iEndPosition, final String iRecordSeparators, final char... iJumpCharacters) { if (iEndPosition == -1) iEndPosition = iSource.length(); final StringBuilder buffer = new StringBuilder(128); for (int i = iStartPosition; i < iEndPosition; ++i) { char c = iSource.charAt(i); if (iRecordSeparators.indexOf(c) > -1) { iParts.add(buffer.toString()); buffer.setLength(0); } else { if (iJumpCharacters.length > 0 && buffer.length() == 0) { // CHECK IF IT'S A CHAR TO JUMP if (!isCharPresent(c, iJumpCharacters)) { buffer.append(c); } } else buffer.append(c); } } if (iJumpCharacters.length > 0 && buffer.length() > 0) { // CHECK THE END OF LAST ITEM IF NEED TO CUT THE CHARS TO JUMP char b; int newSize = 0; boolean found; for (int i = buffer.length() - 1; i >= 0; --i) { b = buffer.charAt(i); found = false; for (char j : iJumpCharacters) { if (j == b) { found = true; ++newSize; break; } } if (!found) break; } if (newSize > 0) buffer.setLength(buffer.length() - newSize); } iParts.add(buffer.toString()); return iParts; } public static int indexOf(final String iSource, final int iBegin, char... iChars) { if (iChars.length == 1) // ONE CHAR: USE JAVA INDEXOF return iSource.indexOf(iChars[0], iBegin); final int len = iSource.length(); for (int i = iBegin; i < len; ++i) { for (int k = 0; k < iChars.length; ++k) { final char c = iSource.charAt(i); if (c == iChars[k]) return i; } } return -1; } public static boolean isCharPresent(final char iCharacter, final char[] iCharacters) { final int len = iCharacters.length; for (int i = 0; i < len; ++i) { if (iCharacter == iCharacters[i]) { return true; } } return false; } }