Java Set to String toString(Set attribute)

Here you can find the source of toString(Set attribute)

Description

Returns first value from a set (used to find values of one-valued attributes)

License

Apache License

Parameter

Parameter Description
attribute set of attributes

Return

single value of an attribute, or null if set is empty

Declaration

public static String toString(Set<String> attribute) 

Method Source Code

//package com.java2s;
/*/*www  .j ava2 s.  com*/
 * Copyright 2012 AMG.lab, a Bull Group Company
 * 
 * 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.
 */

import java.util.Iterator;

import java.util.Set;

public class Main {
    /**
     * Returns first value from a set (used to find values of one-valued attributes)
     * @param attribute set of attributes
     * @return single value of an attribute, or null if set is empty
     */
    public static String toString(Set<String> attribute) {
        Iterator<String> it = attribute.iterator();
        if (it.hasNext()) {
            return it.next();
        }
        return null;
    }
}

Related

  1. toStringArray(final Set set)
  2. toStringSet(String... metrics)