1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Сode optimization Java

Discussion in 'Programming/Internet' started by josef, Oct 8, 2018.

  1. josef

    josef Guest

    This code use 29224 kilobyte of memory. How can I optimize this code? Thank you. maybe I should use composition instead extension. Thank you.

    import java.util.Collection;
    import java.util.HashSet;
    import java.util.Arrays;

    public class JavaApplication8 {
    public static void main(String[] args) {
    CountableHashSet<String> s = new CountableHashSet<>();
    s.addAll(Arrays.asList("Victor", "Nikita", "Soul"));

    public static class CountableHashSet<E> extends HashSet<E> {
    private int count = 0;

    public CountableHashSet(){}

    public CountableHashSet(int initCap, float loadFactor) {
    super(initCap, loadFactor);
    public boolean add(E e) {
    return super.add(e);}
    public boolean addAll(Collection<? extends E> collection) {
    count += collection.size();
    return super.addAll(collection);}

    public int getCount() {return count;}

    Login To add answer/comment

Share This Page