kotlin , Creating an arraylist out of an arrayObject



.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-3















Trying to make an Arraylist out of my obbjects, using the ArrayList of below code .
Here my code is :-



 var i = 1.0
var list: ArrayList<Any> = ArrayList()
while (i <= n)
intPerMonth = P * R
P = P - (e - intPerMonth)
Log.e("TAG", "Month -> " + i.toInt())
Log.e("TAG", "Interest per month -> " + Math.round(intPerMonth))
Log.e("TAG", "Principal per month -> " + Math.round(e - intPerMonth))
Log.e("TAG", "Balance Principal -> " + Math.round(P))
Log.e("TAG", "***************************")

list = arrayListOf(
i.toInt(),
Math.round(intPerMonth),
Math.round(e - intPerMonth),
Math.round(e - intPerMonth),
Math.round(P)
)
i++
Log.e("myArray", list.toString()) // this list.toString() is my output




Output of this Program is



E/myArray: [1, 10, 79, 79, 921]
E/myArray: [2, 9, 80, 80, 842]
E/myArray: [3, 8, 80, 80, 761]



but i want this type of list:-



[(1,10,79,79,921),(2,9,80,80,842),(3,8,80,80,761)]









share|improve this question



















  • 1





    try using ArrayList<ArrayList> type

    – Alesandro Giordano
    Nov 15 '18 at 10:16











  • this is kotlin bro @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:17











  • can you explain in coding? @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:18











  • Yes excuse me, I'll try to simulate it in a console.. wait a moment

    – Alesandro Giordano
    Nov 15 '18 at 10:18











  • ok sure , thank you @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:19

















-3















Trying to make an Arraylist out of my obbjects, using the ArrayList of below code .
Here my code is :-



 var i = 1.0
var list: ArrayList<Any> = ArrayList()
while (i <= n)
intPerMonth = P * R
P = P - (e - intPerMonth)
Log.e("TAG", "Month -> " + i.toInt())
Log.e("TAG", "Interest per month -> " + Math.round(intPerMonth))
Log.e("TAG", "Principal per month -> " + Math.round(e - intPerMonth))
Log.e("TAG", "Balance Principal -> " + Math.round(P))
Log.e("TAG", "***************************")

list = arrayListOf(
i.toInt(),
Math.round(intPerMonth),
Math.round(e - intPerMonth),
Math.round(e - intPerMonth),
Math.round(P)
)
i++
Log.e("myArray", list.toString()) // this list.toString() is my output




Output of this Program is



E/myArray: [1, 10, 79, 79, 921]
E/myArray: [2, 9, 80, 80, 842]
E/myArray: [3, 8, 80, 80, 761]



but i want this type of list:-



[(1,10,79,79,921),(2,9,80,80,842),(3,8,80,80,761)]









share|improve this question



















  • 1





    try using ArrayList<ArrayList> type

    – Alesandro Giordano
    Nov 15 '18 at 10:16











  • this is kotlin bro @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:17











  • can you explain in coding? @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:18











  • Yes excuse me, I'll try to simulate it in a console.. wait a moment

    – Alesandro Giordano
    Nov 15 '18 at 10:18











  • ok sure , thank you @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:19













-3












-3








-3








Trying to make an Arraylist out of my obbjects, using the ArrayList of below code .
Here my code is :-



 var i = 1.0
var list: ArrayList<Any> = ArrayList()
while (i <= n)
intPerMonth = P * R
P = P - (e - intPerMonth)
Log.e("TAG", "Month -> " + i.toInt())
Log.e("TAG", "Interest per month -> " + Math.round(intPerMonth))
Log.e("TAG", "Principal per month -> " + Math.round(e - intPerMonth))
Log.e("TAG", "Balance Principal -> " + Math.round(P))
Log.e("TAG", "***************************")

list = arrayListOf(
i.toInt(),
Math.round(intPerMonth),
Math.round(e - intPerMonth),
Math.round(e - intPerMonth),
Math.round(P)
)
i++
Log.e("myArray", list.toString()) // this list.toString() is my output




Output of this Program is



E/myArray: [1, 10, 79, 79, 921]
E/myArray: [2, 9, 80, 80, 842]
E/myArray: [3, 8, 80, 80, 761]



but i want this type of list:-



[(1,10,79,79,921),(2,9,80,80,842),(3,8,80,80,761)]









share|improve this question
















Trying to make an Arraylist out of my obbjects, using the ArrayList of below code .
Here my code is :-



 var i = 1.0
var list: ArrayList<Any> = ArrayList()
while (i <= n)
intPerMonth = P * R
P = P - (e - intPerMonth)
Log.e("TAG", "Month -> " + i.toInt())
Log.e("TAG", "Interest per month -> " + Math.round(intPerMonth))
Log.e("TAG", "Principal per month -> " + Math.round(e - intPerMonth))
Log.e("TAG", "Balance Principal -> " + Math.round(P))
Log.e("TAG", "***************************")

list = arrayListOf(
i.toInt(),
Math.round(intPerMonth),
Math.round(e - intPerMonth),
Math.round(e - intPerMonth),
Math.round(P)
)
i++
Log.e("myArray", list.toString()) // this list.toString() is my output




Output of this Program is



E/myArray: [1, 10, 79, 79, 921]
E/myArray: [2, 9, 80, 80, 842]
E/myArray: [3, 8, 80, 80, 761]



but i want this type of list:-



[(1,10,79,79,921),(2,9,80,80,842),(3,8,80,80,761)]






android arrays arraylist kotlin






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 10:13









Wesam

66521225




66521225










asked Nov 15 '18 at 10:09









maulik patelmaulik patel

12




12







  • 1





    try using ArrayList<ArrayList> type

    – Alesandro Giordano
    Nov 15 '18 at 10:16











  • this is kotlin bro @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:17











  • can you explain in coding? @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:18











  • Yes excuse me, I'll try to simulate it in a console.. wait a moment

    – Alesandro Giordano
    Nov 15 '18 at 10:18











  • ok sure , thank you @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:19












  • 1





    try using ArrayList<ArrayList> type

    – Alesandro Giordano
    Nov 15 '18 at 10:16











  • this is kotlin bro @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:17











  • can you explain in coding? @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:18











  • Yes excuse me, I'll try to simulate it in a console.. wait a moment

    – Alesandro Giordano
    Nov 15 '18 at 10:18











  • ok sure , thank you @AlesandroGiordano

    – maulik patel
    Nov 15 '18 at 10:19







1




1





try using ArrayList<ArrayList> type

– Alesandro Giordano
Nov 15 '18 at 10:16





try using ArrayList<ArrayList> type

– Alesandro Giordano
Nov 15 '18 at 10:16













this is kotlin bro @AlesandroGiordano

– maulik patel
Nov 15 '18 at 10:17





this is kotlin bro @AlesandroGiordano

– maulik patel
Nov 15 '18 at 10:17













can you explain in coding? @AlesandroGiordano

– maulik patel
Nov 15 '18 at 10:18





can you explain in coding? @AlesandroGiordano

– maulik patel
Nov 15 '18 at 10:18













Yes excuse me, I'll try to simulate it in a console.. wait a moment

– Alesandro Giordano
Nov 15 '18 at 10:18





Yes excuse me, I'll try to simulate it in a console.. wait a moment

– Alesandro Giordano
Nov 15 '18 at 10:18













ok sure , thank you @AlesandroGiordano

– maulik patel
Nov 15 '18 at 10:19





ok sure , thank you @AlesandroGiordano

– maulik patel
Nov 15 '18 at 10:19












1 Answer
1






active

oldest

votes


















0














So it looks like you want a list of lists? Try creating an inner list in every iteration that you then add to your list, like this:



var i = 1.0
var list: ArrayList<Any> = ArrayList()
while (i <= n)
intPerMonth = P * R
P = P - (e - intPerMonth)
Log.e("TAG", "Month -> " + i.toInt())
Log.e("TAG", "Interest per month -> " + Math.round(intPerMonth))
Log.e("TAG", "Principal per month -> " + Math.round(e - intPerMonth))
Log.e("TAG", "Balance Principal -> " + Math.round(P))
Log.e("TAG", "***************************")

var innerList = arrayListOf( // create a different list here
i.toInt(),
Math.round(intPerMonth),
Math.round(e - intPerMonth),
Math.round(e - intPerMonth),
Math.round(P)
)
list.add(innerList) // add the inner list to your list
i++

Log.e("myArray", list.toString()) // this prints the new list of lists





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%2f53316995%2fkotlin-creating-an-arraylist-out-of-an-arrayobject%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









    0














    So it looks like you want a list of lists? Try creating an inner list in every iteration that you then add to your list, like this:



    var i = 1.0
    var list: ArrayList<Any> = ArrayList()
    while (i <= n)
    intPerMonth = P * R
    P = P - (e - intPerMonth)
    Log.e("TAG", "Month -> " + i.toInt())
    Log.e("TAG", "Interest per month -> " + Math.round(intPerMonth))
    Log.e("TAG", "Principal per month -> " + Math.round(e - intPerMonth))
    Log.e("TAG", "Balance Principal -> " + Math.round(P))
    Log.e("TAG", "***************************")

    var innerList = arrayListOf( // create a different list here
    i.toInt(),
    Math.round(intPerMonth),
    Math.round(e - intPerMonth),
    Math.round(e - intPerMonth),
    Math.round(P)
    )
    list.add(innerList) // add the inner list to your list
    i++

    Log.e("myArray", list.toString()) // this prints the new list of lists





    share|improve this answer



























      0














      So it looks like you want a list of lists? Try creating an inner list in every iteration that you then add to your list, like this:



      var i = 1.0
      var list: ArrayList<Any> = ArrayList()
      while (i <= n)
      intPerMonth = P * R
      P = P - (e - intPerMonth)
      Log.e("TAG", "Month -> " + i.toInt())
      Log.e("TAG", "Interest per month -> " + Math.round(intPerMonth))
      Log.e("TAG", "Principal per month -> " + Math.round(e - intPerMonth))
      Log.e("TAG", "Balance Principal -> " + Math.round(P))
      Log.e("TAG", "***************************")

      var innerList = arrayListOf( // create a different list here
      i.toInt(),
      Math.round(intPerMonth),
      Math.round(e - intPerMonth),
      Math.round(e - intPerMonth),
      Math.round(P)
      )
      list.add(innerList) // add the inner list to your list
      i++

      Log.e("myArray", list.toString()) // this prints the new list of lists





      share|improve this answer

























        0












        0








        0







        So it looks like you want a list of lists? Try creating an inner list in every iteration that you then add to your list, like this:



        var i = 1.0
        var list: ArrayList<Any> = ArrayList()
        while (i <= n)
        intPerMonth = P * R
        P = P - (e - intPerMonth)
        Log.e("TAG", "Month -> " + i.toInt())
        Log.e("TAG", "Interest per month -> " + Math.round(intPerMonth))
        Log.e("TAG", "Principal per month -> " + Math.round(e - intPerMonth))
        Log.e("TAG", "Balance Principal -> " + Math.round(P))
        Log.e("TAG", "***************************")

        var innerList = arrayListOf( // create a different list here
        i.toInt(),
        Math.round(intPerMonth),
        Math.round(e - intPerMonth),
        Math.round(e - intPerMonth),
        Math.round(P)
        )
        list.add(innerList) // add the inner list to your list
        i++

        Log.e("myArray", list.toString()) // this prints the new list of lists





        share|improve this answer













        So it looks like you want a list of lists? Try creating an inner list in every iteration that you then add to your list, like this:



        var i = 1.0
        var list: ArrayList<Any> = ArrayList()
        while (i <= n)
        intPerMonth = P * R
        P = P - (e - intPerMonth)
        Log.e("TAG", "Month -> " + i.toInt())
        Log.e("TAG", "Interest per month -> " + Math.round(intPerMonth))
        Log.e("TAG", "Principal per month -> " + Math.round(e - intPerMonth))
        Log.e("TAG", "Balance Principal -> " + Math.round(P))
        Log.e("TAG", "***************************")

        var innerList = arrayListOf( // create a different list here
        i.toInt(),
        Math.round(intPerMonth),
        Math.round(e - intPerMonth),
        Math.round(e - intPerMonth),
        Math.round(P)
        )
        list.add(innerList) // add the inner list to your list
        i++

        Log.e("myArray", list.toString()) // this prints the new list of lists






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 17:15









        TagasTagas

        581517




        581517





























            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%2f53316995%2fkotlin-creating-an-arraylist-out-of-an-arrayobject%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

            How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

            Darth Vader #20

            Ondo