Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8233187

Return empty list if no copies requested in Collections::nCopies

    Details

      Description

      A DESCRIPTION OF THE PROBLEM :
      There exists in the Collections class a method called "nCopies". Optimize this method to return Collections.emptyList() if n equals 0 to avoid instantiating an empty CopiesList object.

          public static <T> List<T> nCopies(int n, T o) {
              if (n < 0)
                  throw new IllegalArgumentException("List length = " + n);
              return new CopiesList<>(n, o);
          }


        Attachments

          Activity

            People

            • Assignee:
              kravikumar Kiran Sidhartha Ravikumar
              Reporter:
              webbuggrp Webbug Group
            • Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

              Dates

              • Created:
                Updated: