Arraylist in kotlin1/5/2024 ![]() ![]() Smaller ASTs explode (are deleted), the same size both explode, and same direction ASTs do nothingĮxplanation: The 10 and -5 collide resulting in 10.Negative numbers move left, positive numbers move right.In package kotlin.Is this a performant strategy to implement a stack in Kotlin to compare and delete values? ExpectĬreate a stack in order to compare an array of asteroids (ASTs) and handle collisions (deletions), returning the final array of ASTs after collisions. We could assume or we can simply go and check how the Kotlin standard library actually implements these things. We can assume that MutableList is simply another interface for ArrayList, I guess. Uhh, exciting!! So, List isn’t really a simple list per se but is actually an interface for ArrayList. In Kotlin, the default implementation of List is ArrayList which you can think of as a resizable array. What peaked my interest was the last sentence of the documentation: ![]() Interfaces, Interfaces, InterfacesĪ quick glance at Kotlin’s documentation provides a good overview about what the difference between them is: while List provides read-only access to stored elements, MutableList provides “list-specific write operations” that allow us to add or remove particular elements from an existing list. ![]() While I have been unsuccessful in my attempts, with the particulars of what I want to do, I learned quite an interesting amount about what makes a List different from a MutableList, and I’ll share a bit more about what I’ve learned here. ![]() My last attempt involves casting immutable lists as mutable lists, in order to modify a supposedly immutable list into a mutable one. I can almost feel your excitement through this screen! In particular, I’ve been trying to investigate and learn ways in which you can break immutability in Kotlin, either knowingly or unknowingly. I’ve been thinking about immutability a lot…interesting, I know. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |