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 Array Problem 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 "Array Problem " Watch "Array Problem " New topic

Array Problem

Rahul Pawar
Ranch Hand

Joined: Mar 13, 2001
Posts: 38
Hi Friends ,
if i mention :
int arr[] = new int{1,2 3,4}; =>it's illegeal
int arr[] = new int[]{1,2,3,4};=>it's legal
can anybody explain me y is it so ?
lee dalais
Ranch Hand

Joined: Feb 28, 2001
Posts: 67
after the 'new' keyword is used in an array declaration, [] is expected to define the dimension(size), so:
int arr[] = new int{1,2 3,4}; is illegal
but below is a legal array construction statement:
int arr[] = new int[]{1,2,3,4};
look here in the JLS
I agree. Here's the link:
subject: Array Problem
It's not a secret anymore!