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;
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
add a comment |
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
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
add a comment |
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
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
arrays kotlin
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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()
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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()
add a comment |
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()
add a comment |
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()
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()
answered Mar 27 at 10:25
SuperSaiyanJSTNSuperSaiyanJSTN
284 bronze badges
284 bronze badges
add a comment |
add a comment |
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.
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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