Declare Multiple Java Arrays on Same Line?

Is it possible to initialize and/or declare multiple arrays in the same line in Java?

ie.

int a, b, c, d, e = 4

works but

int[] a, b, c, d, e, = new int[4] 

doesn't seem to work (size of array is 4)

Answers


Bear in mind that

int a, b, c, d, e = 4;

is declaring 5 ints but only initialising 'e'.

In the same way,

int[] a, b, c, d, e = new int[4];

will only initialise e.

You'd need something like

int[] a=new int[4], b=new int[4], etc...

which frankly, isn't worth one-lining...


Need Your Help

Create new array from integer elements of another array? MATLAB

arrays matlab integer find isinteger

I have created an array tP which contains a mix of integer and non-integer elements. I want to create a new array of the integer element.

Deciding on type in the runtime and applying it in generic type - how can I do this?

c# types

I would like to create a strongly type list and decide the type in runtime. This is my code.I thought it should work, but it doesn't :)

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.