List<InputStream> pdfs = streamOfPDFFiles;
List<PdfReader> readers = new ArrayList<PdfReader>();


I saw many programmers using this syntax .
I didnt get it?
Can anyone help me to expalin this in detail
ie. <InputStream> what does this mean?

and can i implement this same idea with any other code which is simpler?

what's the type of the list\array
the line
List<PdfReader> reader= new ArrayList<PdfRead>();
meaning set a list of pdf readers

If you read up on "Generics" - just search on "java generics" - you'll learn an awful lot about this syntax and why it was added to the language.

AKA parameterized types.

It means in this List, you can only store objects of PdfReader or objects of any subclass of PdfReader. Other types of object can't be stored in this List.

AKA parameterized types.

It means in this List, you can only store objects of PdfReader or objects of any subclass of PdfReader. Other types of object can't be stored in this List.

And, as a consequence, that anything you take from this list is a PDFReader. So you know that you can do something like

for (PDFReader pdfr: listOfPDFReaders)
{
   pdfr.doSomePDFReaderMethod();
}

and both you and the compiler know that it's okay. If it were just a List, untyped, the compiler would have a problem with this, because you could potentially have PDFReaders, Strings, Integers, Files, or any other sort of Object in this list. The compiler has no way of knowing that the object it gets is a PDFReader, so you'd have to do it like this:

for (Object pdfr: listOfPDFReaders)
{
  if (pdfr instanceof PDFReader)
  {
    (PDFReader) pdfr;
    pdfr.doSomePDFReaderMethod();
  }
}

And that's just annoying.

In java you can pass the datatype with the help of this < >.
This feature called "Generics" in java.
ex

class Test<A,B>
{
   public A var1;
   public B var2;
}
class Sample{
   public static void main(String []args) {

         Test<Integer,String> t=new Test<Integer,String>();
          t.var1=10;
          t.var2="Hello";
          System.out.println(t.var1 + " " + t.var2);

         Test<float,char> p=new Test<float,char>();
          p.var1=10.36;
          p.var2='a';
          System.out.println(p.var1 + " " + p.var2);

   }
}

In java you can pass the datatype with the help of this < >.
This feature called "Generics" in java.
ex

class Test<A,B>
{
   public A var1;
   public B var2;
}
class Sample{
   public static void main(String []args) {

         Test<Integer,String> t=new Test<Integer,String>();
          t.var1=10;
          t.var2="Hello";
          System.out.println(t.var1 + " " + t.var2);

         Test<float,char> p=new Test<float,char>();
          p.var1=10.36;
          p.var2='a';
          System.out.println(p.var1 + " " + p.var2);
   }
}

in above example you can decide the datatype of var2,var2 at the time of creating object

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.