This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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

Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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
subject: NullpointerException in Arrays.sort()
Similar Threads
Autoboxing / unboxing
Collection.toArray() method
list and array
LinkedList problem
casting doubt