Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

circular list java

public class CircularList<T> { // Made by Bredo.
    private List<T> list; // Create Raw list.
    public CircularList() {
        this.list = new ArrayList<>(); // Declare.
    }
    public boolean add(T t) {
        return this.list.add(t); // Add to list.
    }
    public boolean remove(T t) {
        return this.list.remove(t); // Remove from list.
    }
    public boolean contain(T t) {
        return this.list.contains(t); // list contain object.
    }
    public T get(int index) {
        if(size() <= 0) throw new NullPointerException(); // throw NullPointerException if list is empty.
        if((index / size()) >= 1) index -= size() * (index / size()); // Check if index is higher than size, if so then minus
        // until index is within size.
        return list.get(index); // return object from list.
    }
    public int size() {
        return list.size(); // list size.
    }
    public List<T> getRawList() {
        return list; // Get raw list, if other methods is needed.
    }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java actionlistener 
Java :: how to add image in title bar in android 
Java :: android view to bitmap 
Java :: android java display icon in action bar 
Java :: android elevation not working 
Java :: how to refresh activity without intent in android 
Java :: java switch class instanceof 
Java :: isprime java 
Java :: primefaces datepicker validation 
Java :: how to play audio files java 
Java :: how to find power of a number in java 
Java :: coding collections clear method java 
Java :: convert hashset to array 
Java :: how to import jframe in java 
Java :: hashtable contains key java 
Java :: paper api maven 
Java :: string to enum java 
Java :: convert local datetime to instant java 
Java :: change java version maven 
Java :: array to arraylist 
Java :: how to check if a char is a letter java 
Java :: localdate add months in java 
Java :: Arraylist string to character java 
Java :: how to destroy activity in android 
Java :: What is null mean in java 
Java :: spring boot sql logging 
Java :: java find time between two dates 
Java :: list set value at index java 
Java :: has integer java 
Java :: java how to print a string[] 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =