Example usage for java.util HashSet toArray

List of usage examples for java.util HashSet toArray

Introduction

In this page you can find the example usage for java.util HashSet toArray.

Prototype

Object[] toArray();

Source Link

Document

Returns an array containing all of the elements in this set.

Usage

From source file:Main.java

public static void main(String[] a) {
    String elements[] = { "A", "B", "C", "D", "E" };
    HashSet<String> set = new HashSet<String>(Arrays.asList(elements));

    Object[] arrObj = set.toArray();

    for (int i = 0; i < arrObj.length; i++) {
        System.out.println(arrObj[i]);
    }//from   w  ww.j  av  a  2s.c  om

    System.out.println(set);
}

From source file:Main.java

public static void main(String[] args) {
    HashSet<Integer> hSet = new HashSet<Integer>();

    hSet.add(new Integer("1"));
    hSet.add(new Integer("2"));
    hSet.add(new Integer("3"));

    Object[] objArray = hSet.toArray();

    for (Object obj : objArray)
        System.out.println(obj);/*from w  w  w.j a v a 2  s.c  o m*/
}

From source file:org.eclipse.jubula.client.analyze.ui.internal.helper.AnalyzeTreeViewerInputHelper.java

/**
 * This method is used to transform a given QueryResult to an Array
 * which can be used as TreeInput/* w  w  w . j av  a  2s .  c  o  m*/
 * 
 * @param object The given Object (a QueryResult)
 * @return returns an Array of the ToplevelCategories 
 */
public static Object[] getTreeInput(Object object) {

    QueryResult qr = (QueryResult) object;

    HashSet<Category> categorySet = new HashSet<Category>();

    for (Map.Entry<Analyze, AnalyzeResult> a : qr.getResultMap().entrySet()) {

        Category c = ExtensionRegistry.getCategory().get(a.getKey().getCategoryID());
        // add the parent category of this category to the categorySet
        categorySet.add(getRoot(c));
    }
    return categorySet.toArray();
}

From source file:tds.student.web.handlers.TestResponseHandler.java

private static void LoadServerLatencyItems(ServerLatency latency, TestResponseReader responseReader) {
    if (responseReader.getResponses().size() == 0)
        return;//from   w w w.  ja va  2  s. com

    HashSet<String> items = new HashSet<String>();
    HashSet<String> pages = new HashSet<String>();

    for (ItemResponseUpdate responseUpdate : responseReader.getResponses()) {
        items.add(Long.toString(responseUpdate.getItemKey()));
        pages.add(Integer.toString(responseUpdate.getPage()));
    }

    latency.setItemList(StringUtils.join(",", items.toArray()));
    latency.setPageList(StringUtils.join(",", pages.toArray()));
}

From source file:jef.tools.ArrayUtils.java

/**
 * ?//from ww w  .j  a  v  a  2s.co  m
 * 
 * @param ls
 * @param ls2
 * @return
 */
public static Object[] intersect(Object[] ls, Object[] ls2) {
    HashSet<Object> set = new HashSet<Object>(Arrays.asList(ls));
    set.retainAll(Arrays.asList(ls2));
    return set.toArray();
}

From source file:jef.tools.ArrayUtils.java

/**
 * ?(??ls??ls2) ???ls??ls2/*from   w  w w. ja  v a  2 s . c om*/
 * 
 * @param ls
 * @param ls2
 * @return
 */
public static Object[] minus(Object[] ls, Object[] ls2) {
    HashSet<Object> set = new HashSet<Object>(Arrays.asList(ls));
    set.removeAll(Arrays.asList(ls2));
    return set.toArray();
}

From source file:com.cyclopsgroup.waterview.velocity.VelocityJellyContextAdapter.java

/**
 * Overwrite or implement method getKeys()
 *
 * @see org.apache.velocity.context.Context#getKeys()
 *///from  w  w w .  j a  va 2s  .c o m
public Object[] getKeys() {
    HashSet keys = new HashSet();
    CollectionUtils.addAll(keys, context.getVariableNames());
    return keys.toArray();
}

From source file:jef.tools.ArrayUtils.java

/**
 * ?/*www  . ja va  2  s  . com*/
 * 
 * @param ls
 * @param ls2
 * @return
 */
public static Object[] union(Object[] ls, Object[] ls2) {
    HashSet<Object> set = new HashSet<Object>(Arrays.asList(ls));
    for (Object o : ls2) {
        set.add(o);
    }
    return set.toArray();
}

From source file:at.ac.univie.isc.asio.security.ExpandAuthoritiesContainerTest.java

@Theory
public void maps_multiple_role_container_to_union(final Role one, final Role two) {
    final HashSet<GrantedAuthority> union = Sets.newHashSet();
    union.add(one);/*from www.  ja  v  a 2 s  . c  om*/
    union.addAll(one.getGrantedAuthorities());
    union.add(two);
    union.addAll(two.getGrantedAuthorities());
    final Object[] expected = union.toArray();
    final Collection<? extends GrantedAuthority> actual = subject.mapAuthorities(Arrays.asList(one, two));
    assertThat(actual, containsInAnyOrder(expected));
}

From source file:geogebra.kernel.optimization.FitRealFunction.java

public void setFunction(Function f) throws Exception {
    kernel = f.getKernel();//from   www.  ja  va  2 s  .  c om
    FunctionVariable fvar = f.getFunctionVariable();

    java.util.HashSet<GeoElement> hash = f.getVariables(); //Get a,b,c,... to array
    if (hash == null) {
        throw (new Exception("No gliders/parameters in fit-function..."));
    } else {
        gliders = hash.toArray();
    } //if no gliders

    numberOfParameters = gliders.length;

    mydoubles = new MyDouble[numberOfParameters]; //Make my own parameters
    double sum = 0.0d; //Sum for average
    double temp;
    for (int i = 0; i < numberOfParameters; i++) {
        temp = ((NumberValue) gliders[i]).getDouble();
        mydoubles[i] = new MyDouble(kernel);
        mydoubles[i].set(temp); //Set mydoubles to start values from a,b,c
        sum += temp; //System.out.println("mydouble["+i+"]: "+mydoubles[i].getDouble());
    } //for all parameters

    ExpressionNode node = f.getExpression();

    ExpressionNode enf = (ExpressionNode) node.deepCopy(kernel); //Make new tree for new function
    //ExpressionNode  enf=new ExpressionNode(kernel,evf);      //System.out.println("enf(fr replace): "+enf.toString());

    for (int i = 0; i < numberOfParameters; i++) {
        enf = enf.replaceAndWrap((ExpressionValue) gliders[i], mydoubles[i].evaluate());
        //System.out.println("Replaced: "+((NumberValue)pars[i]).toString()+"with: "+mydoubles[i].toString());
    } //for all parameters
      //System.out.println("enf(etter replace): "+enf.toString());
    enf.resolveVariables();
    // should we dispose this??? if(this.newf!=null) 
    this.newf = new Function(enf, fvar); //System.out.println("new function: "+newf.toString());

}