aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes scjp 1.5 question related to collections Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "scjp 1.5 question related to collections" Watch "scjp 1.5 question related to collections" New topic
Author

scjp 1.5 question related to collections

vijay umar
Ranch Hand

Joined: Mar 24, 2009
Posts: 100
please help me with the explanation of this code and its answer!


import java.util.*;
public class LongWordFinder
{
public static void main(String[] args)
{
String[] array = { "123", "12345678", "1", "12", "1234567890"};
List<String> list = Arrays.asList(array);
Collection<String> resultList = getLongWords(list);
}
// INSERT DECLARATION HERE
{
Collection<E> longWords = new ArrayList<E>();
for (E word : coll)
if (word.length() > 6) longWords.add(word);
return longWords;
}
}

Which declarations could be inserted at // INSERT DECLARATION HERE so that the program
will compile and run? (Choose all that apply.)

A. public static <E extends CharSequence> Collection<? extends CharSequence>
getLongWords(Collection<E> coll)

B. public static <E extends CharSequence> List<E>
getLongWords(Collection<E> coll)

C. public static Collection<E extends CharSequence>
getLongWords(Collection<E> coll)

D. public static List<CharSequence>
getLongWords(Collection<CharSequence> coll)

E. public static List<? extends CharSequence>
getLongWords(Collection<? extends CharSequence> coll)

F. static public <E extends CharSequence> Collection<E>
getLongWords(Collection<E> coll)

G. static public <E super CharSequence> Collection<E>
getLongWords(Collection<E> coll)


Answer for this is option F

Ruben Soto
Ranch Hand

Joined: Dec 16, 2008
Posts: 1032
Vijay,

First of all, there is a rule that requires that you quote your sources.
Second, this question has been asked before. It might be good if you do a search before asking a question, because many times you will find some good answers already for it: Ultimate Generics Question

Thanks,

Ruben


All code in my posts, unless a source is explicitly mentioned, is my own.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: scjp 1.5 question related to collections
 
Similar Threads
The return type for generics topic that I not clear.
Collections and Generics Help
Generics problem
Ultimate generics Q
E super CharSequence makes no sense??