Array

Download

Download jar file or use maven. psjava requires Java 1.6 (or above)

<dependency>
    <groupId>org.psjava</groupId>
    <artifactId>psjava</artifactId>
    <version>0.1.19</version>
</dependency>

Example Code

// Array interface has only methods for reading.
// Use MutableArray for modification.

MutableArray<String> array = MutableArrayFactory.create(10, "");
array.set(0, "A"); // 0 indexed element is the first value
array.set(9, "B"); // set last value
String first = array.get(0); // must be "A"
int size = array.size(); // 10

// There are several ways to create mutable arrays.

MutableArrayFromVarargs.create("A", "B", "C", "D");
MutableArrayUsingIntArray.wrap(new int[] { 1, 2, 3, 4 }); // There are wrappers for Java's array.
MutableArrayUsingCharArray.wrap(new char[] { 'A', 'B', 'C' });

// There are also several ways to create read only array.

ArrayFromVarargs.create("A", "B", "C");
CharacterArrayUsingString.create("ABC");
UniformArray.create("A", 3);
SubArray.wrap(array, 3, 5); // wraps as 2 sized array

See Also

Implementation


Copyright 2014 psjava team. View on GitHub