• Post Reply Bookmark Topic Watch Topic
  • New Topic

array re-initialization  RSS feed

 
Taras Lukiyanets
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a following question. Suppose that I initialized an array like this:
Object[] params = { new String (ProductName), new String(SupplierName) };

Suppose now I want the same type of array but with different values, though I cannot reuse it like this later on:
Object[] params = { new String(SupplierId) };
Looks like now I need to either initialize the array with 'null' values or create a new array, e.g. 'params1' (which is kind of wasteful and complicates readability of code). Is there other solution? Hmm...
 
Keith Lynn
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Taras Lukiyanets:
I have a following question. Suppose that I initialized an array like this:
Object[] params = { new String (ProductName), new String(SupplierName) };

Suppose now I want the same type of array but with different values, though I cannot reuse it like this later on:
Object[] params = { new String(SupplierId) };
Looks like now I need to either initialize the array with 'null' values or create a new array, e.g. 'params1' (which is kind of wasteful and complicates readability of code). Is there other solution? Hmm...


You can't redeclare the same variable name as long as it is still in scope.

What you can do is include the type of the array in front of the initialization list.

 
Taras Lukiyanets
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Keith, that's exactly what I was looking for! ;-)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!