Java tutorial
//package com.java2s; //License from project: Apache License public class Main { public static final String DEFAULT_CATEGORIES = "no category"; public static String getDefaultCategory(final String categoryString) { String firstCategory = null; final String[] categories = splitCategoryString(categoryString); for (final String cat : categories) { final String category = cat.trim(); if (isDefault(category)) { return category.substring(getNumDashes(category), category.length() - 1); } if (firstCategory == null) { firstCategory = category.substring(getNumDashes(category)); } } return firstCategory; } private static String[] splitCategoryString(final String categoryString) { final String catStr = (categoryString == null ? DEFAULT_CATEGORIES : categoryString); return catStr.split(","); } static boolean isDefault(final String category) { return category.endsWith("*"); } static int getNumDashes(final String category) { int i = 0; while (i < category.length() && (int) category.charAt(i) == (int) '-') { i++; } return i; } }