Java tutorial
//package com.java2s; /** * This file is part of the Open Web Application Security Project (OWASP) Java File IO Security project. For details, please see * <a href="https://www.owasp.org/index.php/OWASP_Java_File_I_O_Security_Project">https://www.owasp.org/index.php/OWASP_Java_File_I_O_Security_Project</a>. * * Copyright (c) 2014 - The OWASP Foundation * * This API is published by OWASP under the Apache 2.0 license. You should read and accept the LICENSE before you use, modify, and/or redistribute this software. * * @author Neil Matatall (neil.matatall .at. gmail.com) - Original ESAPI author * @author August Detlefsen <a href="http://www.codemagi.com">CodeMagi</a> - Java File IO Security Project lead * @created 2014 */ import java.util.Collections; import java.util.HashSet; import java.util.Set; public class Main { /** * Convert a char array to a unmodifiable Set. * * @param array the contents of the new Set * @return a unmodifiable Set containing the elements in the array. */ public static Set<Character> arrayToUnmodifiableSet(char... array) { if (array == null) { return Collections.emptySet(); } if (array.length == 1) { return Collections.singleton(array[0]); } return Collections.unmodifiableSet(arrayToSet(array)); } /** * Converts an array of chars to a Set of Characters. * * @param array the contents of the new Set * @return a Set containing the elements in the array */ public static Set<Character> arrayToSet(char... array) { Set<Character> toReturn; if (array == null) { return new HashSet<Character>(); } toReturn = new HashSet<Character>(array.length); for (char c : array) { toReturn.add(c); } return toReturn; } }