About Question enthuware.ocajp.i.v8.2.1465 :

Help and support on OCA OCP Java Programmer Certification Questions
1Z0-808, 1Z0-809, 1Z0-815, 1Z0-816, 1Z0-817

Moderator: admin

rali14043
Posts: 2
Joined: Sat Jan 19, 2019 4:38 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1465 :

Post by rali14043 »

THe code does not compiles for me since the statement is missing greate than and less than size for a list <>

List s1 = new ArrayList( );

admin
Site Admin
Posts: 10058
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1465 :

Post by admin »

rali14043 wrote:
Wed Feb 13, 2019 1:00 pm
THe code does not compiles for me since the statement is missing greate than and less than size for a list <>

List s1 = new ArrayList( );
Please compile it from command line. There is nothing wrong with it. You will get compiler warning but no error. <> is required only if you are using generics.
If you like our products and services, please help us by posting your review here.

richardsmw0
Posts: 2
Joined: Wed Aug 25, 2021 7:37 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1465 :

Post by richardsmw0 »

Quick question. Shouldn't the List be delcared/defined like this:

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

Is String the default?

admin
Site Admin
Posts: 10058
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: About Question enthuware.ocajp.i.v8.2.1465 :

Post by admin »

No, String is not the default. List s1 = new ArrayList( ); means that it is an untyped List, which means the compiler will not check what you put in that list. For example, s1.add(new Integer(1)); and s1.add("hello"); both will be accepted by the compiler.

But when you do List<String> s1 = new ArrayList<String>( ); the compiler will raise an error if you try to add anything other than a String to the list.

This is a feature of Java called "generics". Please go through this tutorial to understand the basics: https://docs.oracle.com/javase/tutorial ... index.html
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 123 guests