Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Minor] Fill remaining elements with null when provided array is longer #16534

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from

Conversation

tedyu
Copy link
Contributor

@tedyu tedyu commented Jul 5, 2024

In commit 42f267a, RangeSet#toArray() doesn't follow Java's practice of filling extra elements with null.
A sample program demonstrating Java's behavior can be found in the first comment.

This PR modifies toArray so that it follows Java's practice.

The testToArrayWithArrayParameter is modified to reflect the new behavior.

Committer Checklist (excluded from commit message)

  • Verify design and implementation
  • Verify test coverage and CI build status
  • Verify documentation (including upgrade notes)

@tedyu
Copy link
Contributor Author

tedyu commented Jul 5, 2024

import java.util.*;
public class MyClass {
    public static void main(String args[]) {
        // Creating an empty Set
        Set<Integer> abs_col = new HashSet<Integer>();
 
        // Use add() method to add
        // elements into the Set
        abs_col.add(10);
        abs_col.add(15);
        abs_col.add(30);
        abs_col.add(20);
        abs_col.add(5);
        abs_col.add(25);
 
        // Displaying the Set
        System.out.println("The Set: " + abs_col);
 
        // Creating the array and using toArray()
        Integer[] arr = abs_col.toArray(new Integer[10]);
 
        System.out.println("The array is:");
        for (int j = 0; j < arr.length; j++)
            System.out.println(arr[j]);
    }
}

@tedyu
Copy link
Contributor Author

tedyu commented Jul 5, 2024

@rreddy-22 @dajac
Can you review this PR ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant