提供Set的浅表副本,其中省略了被移除的Collection所标识的那些元素。
/* * Copyright Terracotta, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License 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. */ //package com.nowjava; import java.util.Collection;/* 来 自 时 代 J a v a 公 众 号 - nowjava.com*/ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.Map; import java.util.Set; public class Main { /** * Makes a shallow copy of the {@code Set} provided omitting those elements identified by the * {@code Collection} {@code removed}. * * @param source the {@code Set} from which the copy is made * @param removed the elements to omit from the copy * * @return a new, entry-ordered {@code Set} containing the elements from {@code source} less those * specified in {@code removed} */ static Set<String> copyWithout(final Set<String> source, final Collection<String> removed) { final Set<String> copy = new LinkedHashSet<String>(source); copy.removeAll(removed); return copy; } /* 时代Java公众号 提供 */ /** * Makes a shallow copy of the {@code Map} provided omitting those entries identified by the * keys in the {@code Collection} {@code removed}. * * @param source the {@code Map} from which the copy is made * @param removed the keys of the entries to omit from the copy * * @return a new, entry-ordered {@code Map} containing the entries from {@code source} less those * specified in {@code removed} */ static Map<String, String> copyWithout(