| Page 17 of 38 Prev | Index | Next |
from java.util import ArrayList
class CountingArrayList(ArrayList):
def __init__(self):
ArrayList.__init__(self)
self.count = 0L
def get(self, index):
self.count += 1
return ArrayList.get(self, index)
a = CountingArrayList()
a.add(1)
a.add(1)
a.add(2)
a.add(3)
a.add(5)
print "len says: %02d, size says: %02d" % (len(a), a.size())
a.get(0)
a.get(4)
print "accessed %02d times" % (a.count)
| Page 17 of 38 Prev | Index | Next |