Java by API/java.util/LinkedHashSet

Материал из Java эксперт
Перейти к: навигация, поиск

LinkedHashSet: add(Integer e)

 
import java.util.LinkedHashSet;
public class Main {
  public static void main(String[] args) {
    LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();
    System.out.println("Size of LinkedHashSet : " + lhashSet.size());
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
    System.out.println(lhashSet.size());
    lhashSet.remove(new Integer("1"));
    System.out.println(lhashSet.size());
  }
}





LinkedHashSet: isEmpty()

 
       
import java.util.LinkedHashSet;
public class Main {
  public static void main(String[] args) {
    LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
    System.out.println(lhashSet);
    lhashSet.clear();
    System.out.println(lhashSet);
    System.out.println(lhashSet.isEmpty());
  }
}





LinkedHashSet: iterator()

 

import java.util.Iterator;
import java.util.LinkedHashSet;
public class Main {
  public static void main(String[] args) {
    LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
    Iterator itr = lhashSet.iterator();
    while (itr.hasNext()){
      System.out.println(itr.next());
    }
  }
}





LinkedHashSet: remove(Object o)

 
import java.util.LinkedHashSet;
public class Main {
  public static void main(String[] args) {
    LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();
    System.out.println("Size of LinkedHashSet : " + lhashSet.size());
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
    System.out.println(lhashSet.size());
    lhashSet.remove(new Integer("1"));
    System.out.println(lhashSet.size());
  }
}





LinkedHashSet: size()

 
import java.util.LinkedHashSet;
public class Main {
  public static void main(String[] args) {
    LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();
    System.out.println("Size of LinkedHashSet : " + lhashSet.size());
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
    System.out.println(lhashSet.size());
    lhashSet.remove(new Integer("1"));
    System.out.println(lhashSet.size());
  }
}





LinkedHashSet: toArray()

 
import java.util.LinkedHashSet;
public class Main {
  public static void main(String[] args) {
    LinkedHashSet<Integer> lhashSet = new LinkedHashSet<Integer>();
    lhashSet.add(new Integer("1"));
    lhashSet.add(new Integer("2"));
    lhashSet.add(new Integer("3"));
    Object[] objArray = lhashSet.toArray();
    for (Object inte: objArray){
      System.out.println(inte);
    }
  }
}





new LinkedHashSet()

  

import java.util.LinkedHashSet;
import java.util.Set;
public class Main {
  public static Set fill(Set a, int size) {
    for (int i = 0; i < size; i++)
      a.add(new Integer(i));
    return a;
  }
  public static void test(Set a) {
    fill(a, 10);
    System.out.println(a);
  }
  public static void main(String[] args) {
    test(new LinkedHashSet());
  }
}