mutableListOf(mutableListOf()) return an array of array with a size equal to 1 when it's first declaredHow do I determine the size of my array in C?What’s the difference between “Array()” and “[]” while declaring a JavaScript array?Getting a sub-array from an existing arrayGet first key in a (possibly) associative array?Grab a segment of an array in Java without creating a new array on heapAny way to declare an array in-line?How do I declare and initialize an array in Java?How to extend an existing JavaScript array with another array, without creating a new arrayGet the first element of an arrayHow to initialize an array's length in javascript?

Exploiting the delay when a festival ticket is scanned

Should I put my name first, or last in the team members list

How to choose using Collection<Id> rather than Collection<String>, or the opposite?

How to innovate in OR

PCB design using code instead of clicking a mouse?

Avoiding Implicit Conversion in Constructor. Explicit keyword doesn't help here

What clothes would flying-people wear?

Move arrows along a contour

Did Vladimir Lenin have a cat?

What Marvel character has this 'W' symbol?

Security measures that could plausibly last 150+ years?

How can flights operated by the same company have such different prices when marketed by another?

Can machine learning learn a function like finding maximum from a list?

Why does the Rust compiler not optimize code assuming that two mutable references cannot alias?

Raindrops in Python

left ... right make different sizes in numerator and denominator

How to efficiently shred a lot of cabbage?

"DDoouubbllee ssppeeaakk!!"

Verb Classification of あげる (to give)

Microgravity indicators

Why did I lose on time with 3 pawns vs Knight. Shouldn't it be a draw?

Rampant sharing of authorship among colleagues in the name of "collaboration". Is not taking part in it a death knell for a future in academia?

How would a lunar colony attack Earth?

Why does one get the wrong value when printing counters together?



mutableListOf(mutableListOf()) return an array of array with a size equal to 1 when it's first declared


How do I determine the size of my array in C?What’s the difference between “Array()” and “[]” while declaring a JavaScript array?Getting a sub-array from an existing arrayGet first key in a (possibly) associative array?Grab a segment of an array in Java without creating a new array on heapAny way to declare an array in-line?How do I declare and initialize an array in Java?How to extend an existing JavaScript array with another array, without creating a new arrayGet the first element of an arrayHow to initialize an array's length in javascript?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















When I create a matrix (Array of Array) with the following declaration the returned size is 1 instead of 0 :



var matrix: MutableList<MutableList<Cell>> = mutableListOf(mutableListOf())


which lead to having a size equal to 2 when I add the first array to the matrix :



matrix.add(lineOfCells)


matrix now contain a first empty array at index 0 and lineOfCells array at index 1, but what I'm looking for is just to have lineOfCells at index 0.










share|improve this question



















  • 4





    Well, yes, since mutableListOf() creates and returns a List, and you're thus creatng a list containing a list. Just don't: var matrix: MutableList<MutableList<Cell>> = mutableListOf()

    – JB Nizet
    Mar 26 at 22:48


















0















When I create a matrix (Array of Array) with the following declaration the returned size is 1 instead of 0 :



var matrix: MutableList<MutableList<Cell>> = mutableListOf(mutableListOf())


which lead to having a size equal to 2 when I add the first array to the matrix :



matrix.add(lineOfCells)


matrix now contain a first empty array at index 0 and lineOfCells array at index 1, but what I'm looking for is just to have lineOfCells at index 0.










share|improve this question



















  • 4





    Well, yes, since mutableListOf() creates and returns a List, and you're thus creatng a list containing a list. Just don't: var matrix: MutableList<MutableList<Cell>> = mutableListOf()

    – JB Nizet
    Mar 26 at 22:48














0












0








0








When I create a matrix (Array of Array) with the following declaration the returned size is 1 instead of 0 :



var matrix: MutableList<MutableList<Cell>> = mutableListOf(mutableListOf())


which lead to having a size equal to 2 when I add the first array to the matrix :



matrix.add(lineOfCells)


matrix now contain a first empty array at index 0 and lineOfCells array at index 1, but what I'm looking for is just to have lineOfCells at index 0.










share|improve this question














When I create a matrix (Array of Array) with the following declaration the returned size is 1 instead of 0 :



var matrix: MutableList<MutableList<Cell>> = mutableListOf(mutableListOf())


which lead to having a size equal to 2 when I add the first array to the matrix :



matrix.add(lineOfCells)


matrix now contain a first empty array at index 0 and lineOfCells array at index 1, but what I'm looking for is just to have lineOfCells at index 0.







arrays kotlin






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 26 at 21:23









ChuloChulo

5,83911 gold badges47 silver badges67 bronze badges




5,83911 gold badges47 silver badges67 bronze badges










  • 4





    Well, yes, since mutableListOf() creates and returns a List, and you're thus creatng a list containing a list. Just don't: var matrix: MutableList<MutableList<Cell>> = mutableListOf()

    – JB Nizet
    Mar 26 at 22:48













  • 4





    Well, yes, since mutableListOf() creates and returns a List, and you're thus creatng a list containing a list. Just don't: var matrix: MutableList<MutableList<Cell>> = mutableListOf()

    – JB Nizet
    Mar 26 at 22:48








4




4





Well, yes, since mutableListOf() creates and returns a List, and you're thus creatng a list containing a list. Just don't: var matrix: MutableList<MutableList<Cell>> = mutableListOf()

– JB Nizet
Mar 26 at 22:48






Well, yes, since mutableListOf() creates and returns a List, and you're thus creatng a list containing a list. Just don't: var matrix: MutableList<MutableList<Cell>> = mutableListOf()

– JB Nizet
Mar 26 at 22:48













1 Answer
1






active

oldest

votes


















1














You have an [0][0] cell, what looks like[[]] this, from the beginning so it means when you are adding one you have a second line of cells.
Or try
var matrix: MutableList> = mutableListOf()






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366396%2fmutablelistofmutablelistof-return-an-array-of-array-with-a-size-equal-to-1-w%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You have an [0][0] cell, what looks like[[]] this, from the beginning so it means when you are adding one you have a second line of cells.
    Or try
    var matrix: MutableList> = mutableListOf()






    share|improve this answer





























      1














      You have an [0][0] cell, what looks like[[]] this, from the beginning so it means when you are adding one you have a second line of cells.
      Or try
      var matrix: MutableList> = mutableListOf()






      share|improve this answer



























        1












        1








        1







        You have an [0][0] cell, what looks like[[]] this, from the beginning so it means when you are adding one you have a second line of cells.
        Or try
        var matrix: MutableList> = mutableListOf()






        share|improve this answer













        You have an [0][0] cell, what looks like[[]] this, from the beginning so it means when you are adding one you have a second line of cells.
        Or try
        var matrix: MutableList> = mutableListOf()







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Mar 27 at 10:25









        SuperSaiyanJSTNSuperSaiyanJSTN

        284 bronze badges




        284 bronze badges





















            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







            Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55366396%2fmutablelistofmutablelistof-return-an-array-of-array-with-a-size-equal-to-1-w%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript