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

            SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

            은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현