سؤال

I want to create a ArrayList of String's ArrayList in Jython.

In Java should be something like:

ArrayList<ArrayList<String>> arr = new ArrayList<ArrayList<String>>()

I dont know how to do that in Jython. The problem is that in Jython even the creation of a simple ArrayList is a bit different. As long as I know, you dont even to define the type:

import java.util.ArrayList as ArrayList
arr = ArrayList()

So how can I create a ArrayList of ArraList in Jython?

I dont even know if it's possible, because as you can read on the documentation it seems to have a bit of limitation.

Java collection objects could act as a Jython object, but Jython objects could not act as Java objects. For instance, it is possible to use a Java ArrayList in Jython and use methods such as add(), remove(), and get()

Thanks in advance.

هل كانت مفيدة؟

المحلول

In Order to implement ArrayList of String's ArrayList you can use the fact that the List's stores Objects in them and ArrayList itself is an Object. so you can do something like this:

import java.util.ArrayList as ArrayList
arr1 = ArrayList()
arr2 = ArrayList()
arr3 = ArrayList()

arr2.add("First")
arr2.add("second")

arr3.add("Third")
arr4.add("Fourth")

arr1.add(arr2)
arr1.add(arr3)

Hope this gives you the idea.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top