CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2005
    Posts
    62

    what does this mean? new String() {...}

    Hi,

    Java beginner here, moving from C++. What does the bracket mean after a new?
    Code:
    protected String[] name = new String[] {
    		Integer.toString(1),
     Integer.toString(2)
     	};

  2. #2
    Join Date
    Feb 2004
    Location
    USA - Florida
    Posts
    729

    Re: what does this mean? new String() {...}

    I assume you mean the curly braces ({}). In the code snippet you posted, they mean initialize the array with the following values.
    Hungarian notation, reinterpreted? http://www.joelonsoftware.com/articles/Wrong.html

  3. #3
    Join Date
    Jun 2002
    Location
    Moscow, Russia.
    Posts
    2,176

    Re: what does this mean? new String() {...}

    You don't need new to initialize array like this. And why is that Integer.toString(1) instead of just "1"? The code you posted is equivalent with:
    Code:
    protected String[] name={"1","2"};
    "Programs must be written for people to read, and only incidentally for machines to execute."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured