We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Is there a way to use ArrayList in Python mode? Thanks!
Certainly, we just need to import it: :D from java.util import ArrayList or import java.util.ArrayList as ArrayList
from java.util import ArrayList
import java.util.ArrayList as ArrayList
# forum.Processing.org/two/discussion/14785/arraylist-in-python-mode # GoToLoop (2016-Feb-06) # import java.util.ArrayList as ArrayList from java.util import ArrayList myJavaList = ArrayList() myJavaList.add(TAU) myJavaList.add('Jython') myJavaList.add(PVector.random3D(this)) print myJavaList print ENTER + `myJavaList.size()` + ', ' + `len(myJavaList)` print myJavaList.get(1) + ', ' + myJavaList[1] + ENTER for item in myJavaList: print item exit()
As you can see above, it accepts any datatype. I couldn't find any way to force a generic type though. 3:-O
However Python already got its own list. Which is more appropriate and no need to import it: :-bd http://py.Processing.org/reference/indexbrackets.html
# forum.Processing.org/two/discussion/14785/arraylist-in-python-mode # GoToLoop (2016-Feb-06) # myPythonList = [] # myPythonList.append(TAU) # myPythonList.append('Jython') # myPythonList.append(PVector.random3D(this)) myPythonList = [TAU, 'Jython', PVector.random3D(this)] print myPythonList print ENTER + `myPythonList.__len__()` + ', ' + `len(myPythonList)` print myPythonList.__getitem__(1) + ', ' + myPythonList[1] + ENTER for item in myPythonList: print item exit()
Answers
Certainly, we just need to import it: :D
from java.util import ArrayList
orimport java.util.ArrayList as ArrayList
As you can see above, it accepts any datatype. I couldn't find any way to force a generic type though. 3:-O
However Python already got its own list. Which is more appropriate and no need to import it: :-bd
http://py.Processing.org/reference/indexbrackets.html