Monday, December 27, 2010

Difference between HashMap and HashTable


HashMap and HashTable both are keyValue Entry they don’t guarantee the order of key value.
HashMap can store null key and Value but HashTable don’t  allow null key or Value.
HashMap is not thread safe but Hash Table is thread safe.
HashTable is synchronized but HashMap is not synchronized.
HashTable is legacy class but Hash Map Is not a legacy class.
Hash Map is more efficient than Hash Table because hashmap is not synchronized so it performs faster than hashtable.

Sorting ArrayList In Decending Order

public void decendingArrayList()
    {
        ArrayList al=new ArrayList();
        al.add(20);
        al.add(30);
        al.add(10);
        al.add(3);
        al.add(2);
        al.add(5);
        System.out.println("Initaily ArrayList:::::::::::: "+al);
       
        Comparator comp=Collections.reverseOrder();
        Collections.sort(al,comp);
        System.out.println("Decending ArrayList::::::::::::::::: "+al);
    }

Monday, December 13, 2010

Pdf Text Extractor using java

We can extract text from pdf file using itext 2.1.6

 PdfReader readerN = new PdfReader("pdfFilename");
            OutputStreamWriter out = new OutputStreamWriter( new FileOutputStream(new File("textFileName")),"Cp1252");

            PdfTextExtractor parse = new PdfTextExtractor(readerN);
            int nrPages = readerN.getNumberOfPages();
           for (int i=2; i<nrPages-2 ; i++) {
                index++;
                 String page = parse.getTextFromPage(i);
                if(page != null){
                    page = page.replace(new StringBuffer("null"), new StringBuffer("??"));
           
                    out.write(page);

Spring Boot Config Server and Config Client.

 In Spring cloud config we can externalise our configuration files to some repository like GIT HUT, Amazon S3 etc. Benefit of externalising ...