Double Curley Braces {{ the hidden functionality

If we have to create a set or list so we have to code like this

List<String> list=new ArrayList<String>();

list.add(“a”); list.add(“b”);

But there is feature in java that we don’t have to use variable again and again,below is the example

List<String> list = new ArrayList<String>() {{
add(“XZ13s”);
add(“AB21/X”);
add(“YYLEX”);
add(“AR2D”);
}};

Advertisements

4 thoughts on “Double Curley Braces {{ the hidden functionality

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s