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 String to a unmodifiable set of characters. * * @param str The string to convert * @return A set containing the characters in str. A empty set is returned if str is null. */ public static Set<Character> strToUnmodifiableSet(String str) { if (str == null) { return Collections.emptySet(); } if (str.length() == 1) { return Collections.singleton(str.charAt(0)); } return Collections.unmodifiableSet(strToSet(str)); } /** * Convert a String to a set of characters. * * @param str The string to convert * @return A set containing the characters in str. A empty set is returned if str is null. */ public static Set<Character> strToSet(String str) { Set<Character> set; if (str == null) { return new HashSet<Character>(); } set = new HashSet<Character>(str.length()); for (int i = 0; i < str.length(); i++) { set.add(str.charAt(i)); } return set; } }