JAVA 8 : How to initialize List Of List in one line [closed]










-5















Hello i want to initialize List Of list in one line



List<List<Integer>> list = .....;


Thanks










share|improve this question













closed as unclear what you're asking by Andy Turner, Roddy of the Frozen Peas, rgettman, khelwood, Shiladitya Nov 14 '18 at 2:31


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • There's a very complete answer over here already: stackoverflow.com/a/47288158/236528

    – mjuarez
    Nov 13 '18 at 21:26






  • 2





    What do you want to initialise it to?

    – khelwood
    Nov 13 '18 at 21:29















-5















Hello i want to initialize List Of list in one line



List<List<Integer>> list = .....;


Thanks










share|improve this question













closed as unclear what you're asking by Andy Turner, Roddy of the Frozen Peas, rgettman, khelwood, Shiladitya Nov 14 '18 at 2:31


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.


















  • There's a very complete answer over here already: stackoverflow.com/a/47288158/236528

    – mjuarez
    Nov 13 '18 at 21:26






  • 2





    What do you want to initialise it to?

    – khelwood
    Nov 13 '18 at 21:29













-5












-5








-5








Hello i want to initialize List Of list in one line



List<List<Integer>> list = .....;


Thanks










share|improve this question














Hello i want to initialize List Of list in one line



List<List<Integer>> list = .....;


Thanks







java list arraylist






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 13 '18 at 21:22









CHARAFI SaadCHARAFI Saad

433517




433517




closed as unclear what you're asking by Andy Turner, Roddy of the Frozen Peas, rgettman, khelwood, Shiladitya Nov 14 '18 at 2:31


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.









closed as unclear what you're asking by Andy Turner, Roddy of the Frozen Peas, rgettman, khelwood, Shiladitya Nov 14 '18 at 2:31


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.














  • There's a very complete answer over here already: stackoverflow.com/a/47288158/236528

    – mjuarez
    Nov 13 '18 at 21:26






  • 2





    What do you want to initialise it to?

    – khelwood
    Nov 13 '18 at 21:29

















  • There's a very complete answer over here already: stackoverflow.com/a/47288158/236528

    – mjuarez
    Nov 13 '18 at 21:26






  • 2





    What do you want to initialise it to?

    – khelwood
    Nov 13 '18 at 21:29
















There's a very complete answer over here already: stackoverflow.com/a/47288158/236528

– mjuarez
Nov 13 '18 at 21:26





There's a very complete answer over here already: stackoverflow.com/a/47288158/236528

– mjuarez
Nov 13 '18 at 21:26




2




2





What do you want to initialise it to?

– khelwood
Nov 13 '18 at 21:29





What do you want to initialise it to?

– khelwood
Nov 13 '18 at 21:29












2 Answers
2






active

oldest

votes


















1














List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));


In Java 9+ you can replace Arrays.asList() with List.of().






share|improve this answer
































    1














    List<List<Integer>> list = 
    Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));





    share|improve this answer

























    • Why so defensive?

      – shmosel
      Nov 13 '18 at 21:37











    • @shmosel what do you mean?

      – Liad Saubron
      Nov 13 '18 at 21:39






    • 2





      Why do you need to copy it to a new ArrayList?

      – shmosel
      Nov 13 '18 at 21:42











    • edited, thanks! @shmosel

      – Liad Saubron
      Nov 14 '18 at 8:09

















    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));


    In Java 9+ you can replace Arrays.asList() with List.of().






    share|improve this answer





























      1














      List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));


      In Java 9+ you can replace Arrays.asList() with List.of().






      share|improve this answer



























        1












        1








        1







        List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));


        In Java 9+ you can replace Arrays.asList() with List.of().






        share|improve this answer















        List<List<Integer>> list = Arrays.asList(Arrays.asList(1,2), Arrays.asList(3,4));


        In Java 9+ you can replace Arrays.asList() with List.of().







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 13 '18 at 22:15









        shmosel

        36.3k43994




        36.3k43994










        answered Nov 13 '18 at 22:03









        MaltMalt

        16.8k34163




        16.8k34163























            1














            List<List<Integer>> list = 
            Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));





            share|improve this answer

























            • Why so defensive?

              – shmosel
              Nov 13 '18 at 21:37











            • @shmosel what do you mean?

              – Liad Saubron
              Nov 13 '18 at 21:39






            • 2





              Why do you need to copy it to a new ArrayList?

              – shmosel
              Nov 13 '18 at 21:42











            • edited, thanks! @shmosel

              – Liad Saubron
              Nov 14 '18 at 8:09















            1














            List<List<Integer>> list = 
            Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));





            share|improve this answer

























            • Why so defensive?

              – shmosel
              Nov 13 '18 at 21:37











            • @shmosel what do you mean?

              – Liad Saubron
              Nov 13 '18 at 21:39






            • 2





              Why do you need to copy it to a new ArrayList?

              – shmosel
              Nov 13 '18 at 21:42











            • edited, thanks! @shmosel

              – Liad Saubron
              Nov 14 '18 at 8:09













            1












            1








            1







            List<List<Integer>> list = 
            Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));





            share|improve this answer















            List<List<Integer>> list = 
            Arrays.asList(Arrays.asList(1,2,3), Arrays.asList(4,5,6));






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 14 '18 at 8:09

























            answered Nov 13 '18 at 21:29









            Liad SaubronLiad Saubron

            794




            794












            • Why so defensive?

              – shmosel
              Nov 13 '18 at 21:37











            • @shmosel what do you mean?

              – Liad Saubron
              Nov 13 '18 at 21:39






            • 2





              Why do you need to copy it to a new ArrayList?

              – shmosel
              Nov 13 '18 at 21:42











            • edited, thanks! @shmosel

              – Liad Saubron
              Nov 14 '18 at 8:09

















            • Why so defensive?

              – shmosel
              Nov 13 '18 at 21:37











            • @shmosel what do you mean?

              – Liad Saubron
              Nov 13 '18 at 21:39






            • 2





              Why do you need to copy it to a new ArrayList?

              – shmosel
              Nov 13 '18 at 21:42











            • edited, thanks! @shmosel

              – Liad Saubron
              Nov 14 '18 at 8:09
















            Why so defensive?

            – shmosel
            Nov 13 '18 at 21:37





            Why so defensive?

            – shmosel
            Nov 13 '18 at 21:37













            @shmosel what do you mean?

            – Liad Saubron
            Nov 13 '18 at 21:39





            @shmosel what do you mean?

            – Liad Saubron
            Nov 13 '18 at 21:39




            2




            2





            Why do you need to copy it to a new ArrayList?

            – shmosel
            Nov 13 '18 at 21:42





            Why do you need to copy it to a new ArrayList?

            – shmosel
            Nov 13 '18 at 21:42













            edited, thanks! @shmosel

            – Liad Saubron
            Nov 14 '18 at 8:09





            edited, thanks! @shmosel

            – Liad Saubron
            Nov 14 '18 at 8:09



            Popular posts from this blog

            Kleinkühnau

            Makov (Slowakei)

            Deutsches Schauspielhaus