Informatix Expert Licensed User Longtime User Jul 15, 2013 #1 I thought this code: Code: Dim ListeTas As List ListeTas.Initialize2(Array As Int(0, 1, 2, 3)) ...was similar to that one: Code: Dim ListeTas As List ListeTas.Initialize For i = 0 To 3 ListeTas.Add(i) Next ...but it seems it's not the case because the first case returns an error (Unsupported Operation Exception) when I try to remove the first element (ListeTas.RemoveAt(0)).
I thought this code: Code: Dim ListeTas As List ListeTas.Initialize2(Array As Int(0, 1, 2, 3)) ...was similar to that one: Code: Dim ListeTas As List ListeTas.Initialize For i = 0 To 3 ListeTas.Add(i) Next ...but it seems it's not the case because the first case returns an error (Unsupported Operation Exception) when I try to remove the first element (ListeTas.RemoveAt(0)).
agraham Expert Licensed User Longtime User Jul 15, 2013 #2 I don't know why Erel designed it this way, I think he might have been trying to make the Array and Lisr APIs similar. Initialize sets the internal object to a Java ArrayList whereas Initialize2 sets it to a Java Arrays.asList(Object[]) which returns a fixed size List which is not an actual Java List but an internal type of List. I did at one time check its actual type, but I've forgotten what it is now.
I don't know why Erel designed it this way, I think he might have been trying to make the Array and Lisr APIs similar. Initialize sets the internal object to a Java ArrayList whereas Initialize2 sets it to a Java Arrays.asList(Object[]) which returns a fixed size List which is not an actual Java List but an internal type of List. I did at one time check its actual type, but I've forgotten what it is now.
icefairy333 Active Member Licensed User Longtime User Jul 15, 2013 #3 I think Code: ListeTas.Initialize2(Array As Int(0, 1, 2, 3)) this one make a readonly list.
Erel B4X founder Staff member Licensed User Longtime User Jul 15, 2013 #4 See the documentation of Initialize2: Basic4android - Collections (Core)
Informatix Expert Licensed User Longtime User Jul 15, 2013 #5 Erel said: See the documentation of Initialize2: Basic4android - Collections (Core) Click to expand... Sorry. I should have read it.
Erel said: See the documentation of Initialize2: Basic4android - Collections (Core) Click to expand... Sorry. I should have read it.