Here you can find the source of splitStructs(String str, char separator)
private static String[] splitStructs(String str, char separator)
//package com.java2s; /**/*from www.j a va2s. com*/ * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file * except in compliance with the License. A copy of the License is located at * * ??? http://aws.amazon.com/apache2.0/ * * or in the "LICENSE.TXT" file accompanying this file. This file 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. */ import java.util.ArrayList; public class Main { private static String[] splitStructs(String str, char separator) { if (str == null) { return null; } int len = str.length(); if (len == 0) { return null; } ArrayList<String> list = new ArrayList<String>(); int index = 0; int start = 0; int match = 0; while (index < len) { if (str.charAt(index) == '<') { match++; } else if (str.charAt(index) == '>') { match--; } else if (str.charAt(index) == separator) { if (match == 0) { list.add(str.substring(start, index).trim()); start = ++index; continue; } } index++; } if (match != 0) { return null; } list.add(str.substring(start, index).trim()); String[] result = new String[list.size()]; list.toArray(result); return result; } }