File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes NullpointerException in Arrays.sort() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "NullpointerException in Arrays.sort()" Watch "NullpointerException in Arrays.sort()" New topic

NullpointerException in Arrays.sort()

amarkirt saroay
Ranch Hand

Joined: Mar 16, 2008
Posts: 167

Why it gives runtime exception of Nullpointer in line 1?

Srividhya Kiran
Ranch Hand

Joined: Feb 17, 2008
Posts: 166

When you create Integer[] y=new Integer[10];

By default, null values will be assigned to Integer Array Object 'y'.

Therefore sorting the array with null values returns in NullPointerException

Ben Souther

Joined: Dec 11, 2004
Posts: 13410


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I agree. Here's the link:
subject: NullpointerException in Arrays.sort()
It's not a secret anymore!