Class CollectionConversions

java.lang.Object
com.cedarsoftware.util.convert.CollectionConversions

public final class CollectionConversions extends Object
Converts between arrays and collections while preserving collection characteristics. Handles conversion from arrays to various collection types including:
  • JDK collections (ArrayList, HashSet, etc.)
  • Concurrent collections (ConcurrentSet, etc.)
  • Special collections (Unmodifiable, Synchronized, etc.)
  • Cedar Software collections (CaseInsensitiveSet, CompactSet, etc.)
The most specific matching collection type is used when converting, and collection characteristics are preserved. For example, converting to a Set from a source that maintains order will result in an ordered Set implementation.
Author:
John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC

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

License

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.
  • Method Details

    • arrayToCollection

      public static <T extends Collection<?>> T arrayToCollection(Object array, Class<T> targetType)
      Converts an array to a collection, supporting special collection types and nested arrays.
      Type Parameters:
      T - The collection class to return
      Parameters:
      array - The source array to convert
      targetType - The target collection type
      Returns:
      A collection of the specified target type
    • collectionToCollection

      public static Object collectionToCollection(Collection<?> source, Class<?> targetType)
      Converts a collection to another collection type, preserving characteristics.
      Parameters:
      source - The source collection to convert
      targetType - The target collection type
      Returns:
      A collection of the specified target type