B4J Question How to iterate through a Java set, in B4J?

B4JExplorer

Active Member
Licensed User
Longtime User
Sets don't have a get() method, because of the non-order.

Do I need to use an Iterator JavaObject, or is there a more direct way?
 

B4JExplorer

Active Member
Licensed User
Longtime User
You can use a iterator or convert the set to an array.
I'm trying to minimize the number of JavaObjects, which I would need to use for an Iterator.

So the only other way, is to do a conversion first, to an array? Ok, thanks.
 
Upvote 0

B4JExplorer

Active Member
Licensed User
Longtime User
I thought for sure, it would be more complicated than this. But this works fine

B4X:
			Private jo_Iterator As JavaObject
			jo_Iterator = jo_Structure.RunMethod( "iterator", Null )
			Private jo_Element As JavaObject

			Do While jo_Iterator.RunMethod( "hasNext", Null )
				jo_Element = jo_Iterator.RunMethod( "next", Null )
				Log( "Next Element " & jo_Element )
			Loop

Issue closed.
 
Upvote 0
Top