• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

array re-initialization

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
Ranch Hand
Posts: 2412
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Keith, that's exactly what I was looking for! ;-)
 
reply
    Bookmark Topic Watch Topic
  • New Topic