Uploaded image for project: 'Commons Lang'
  1. Commons Lang
  2. LANG-1402

ArrayUtils should have null and index-safe get methods.

    XMLWordPrintableJSON

Details

    • New Feature
    • Status: Closed
    • Minor
    • Resolution: Implemented
    • None
    • 3.8
    • General
    • None

    Description

      There should be a safe way to retrieve a value from array without having to check for null and length. It would be a very simple implementation but could save developers a great deal of time in writing and testing.

       

      Something like 

       

      String[] a = null;
      ArrayUtils.get(a, 5); //returns null
      a = new String[5];
      ArrayUtils.get(a, 10); // returns null
       
      a[0] = "Hello World";
      ArrayUtils.get(a, 0); // returns "Hello World"
      

       

       We could handle a few other cases - a default return value. The tricky/annoying thing is the need to cast everything in order to make this 

      Attachments

        Issue Links

          Activity

            People

              chtompki Rob Tompkins
              MarkDacek Mark Dacek
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Time Tracking

                  Estimated:
                  Original Estimate - 24h
                  24h
                  Remaining:
                  Remaining Estimate - 24h
                  24h
                  Logged:
                  Time Spent - Not Specified
                  Not Specified