Skip to content

Instantly share code, notes, and snippets.

@asceth
Created February 18, 2014 04:04
Show Gist options
  • Save asceth/9064457 to your computer and use it in GitHub Desktop.
Save asceth/9064457 to your computer and use it in GitHub Desktop.
public class IntArray {
final int DEFAULT_SIZE = 10;
int[] _int_array;
public IntArray() {
_int_array = new int[DEFAULT_SIZE];
}
public IntArray(int size) {
_int_array = new int[size];
}
public IntArray(int[] copy) {
_int_array = copy;
}
public int get(int index) {
return _int_array[index];
}
public boolean set(int index, int value) {
_int_array[index] = value;
return true;
}
public int size() {
return _int_array.length;
}
public void reinitialize_with_default(int default_value) {
// no need to actually re-create just loop through it
for(int i = 0; i < _int_array.length; i++) {
_int_array[i] = default_value;
}
}
public static void main(String []args){
IntArray int_array = new IntArray();
int_array.reinitialize_with_default(4);
int_array.set(3, 30);
System.out.println("Index - Value");
for (int i = 0; i < int_array.size(); i++) {
System.out.println("" + i + " - " + int_array.get(i));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment