Java Reference
In-Depth Information
return
return null
null ;
}
return
return stack [ depth - 1 ];
}
public
public boolean
boolean hasNext () {
return
return depth > 0 ;
}
public
public boolean
boolean hasRoom () {
return
return depth < stack . length ;
}
public
public int
int getStackDepth () {
return
return depth ;
}
}
This version has a lot more error checking (and a unit test, in the src/test/java/structure
folder), as well as some additional methods not in the original (e.g., hasRoom() —unlike the
full-blown java.util.Stack , this one does not expand beyond its original size, so we need
a way to see if it is full without throwing an exception).
For an example of the “real” java.util.Stack in operation, Handling Very Large Numbers
provides a simple stack-based numeric calculator.
Multidimensional Structures
Problem
You need a two-, three-, or more dimensional array or ArrayList .
Solution
No problem. Java supports this.
Search WWH ::




Custom Search