1

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.

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.