Java tutorial
//package com.java2s; /* *********************************************************************** * * project: org.matsim.* * * * *********************************************************************** * * * * copyright : (C) 2010 by the members listed in the COPYING, * * LICENSE and WARRANTY file. * * email : info at matsim dot org * * * * *********************************************************************** * * * * This program is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * * the Free Software Foundation; either version 2 of the License, or * * (at your option) any later version. * * See also COPYING, LICENSE and WARRANTY file * * * * *********************************************************************** */ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; public class Main { public static final Set<String> stringArrayToSet(final String[] array) { if (array == null) { return Collections.emptySet(); } Set<String> tmp = new LinkedHashSet<>(); for (String part : array) { String trimmed = part.trim(); if (trimmed.length() > 0) { tmp.add(trimmed.intern()); } } return tmp; } }