Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java stack with max size

import java.util.Stack;

public class SizedStack<T> extends Stack<T> {
    private int maxSize;

    public SizedStack(int size) {
        super();
        this.maxSize = size;
    }

    @Override
    public T push(T object) {
        //If the stack is too big, remove elements until it's the right size.
        while (this.size() >= maxSize) {
            this.remove(0);
        }
        return super.push(object);
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: input 3 int 1 line in java 
Java :: ArrayIndexOutOfBoundsException 
Java :: get sum of int array and return string 
Java :: Java array repeating 
Java :: get image from resourcestream javafx 
Java :: write ajva program to vheck if anumber is less than 20 and greater than 5. It generates the exception out of range otherwise. If the number is within the range , then it displays the square of that number. 
Java :: Simple Write a simple Java program that prints a staircase or a figure as show 
Java :: how to extract image from server url and store it in a folder in java 
Java :: java scanner tokens with withespace 
Sql :: mysql set safe mode off 
Sql :: mysql create user with mysql_native_password 
Sql :: select not matching data from two tables 
Sql :: mysql now format 
Sql :: get role postgres 
Sql :: mysql where column not integer 
Sql :: list all triggers in sql server 
Sql :: sqlalchemy_database_uri for mysql 
Sql :: postgresql db owner change 
Sql :: UseSqlServer no definition 
Sql :: oracle table size 
Sql :: c# datetime to sql server datetime 
Sql :: fetch first 10 rows in oracle sql developer 
Sql :: wordpress change url in database 
Sql :: group_concat length limit 
Sql :: add sequence postgres 
Sql :: find a column in all tables postgres 
Sql :: postgres select from last 3 months 
Sql :: mysql not supported auth mode 
Sql :: show all tables in oracle 
Sql :: set sequence value oracle 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =