Monthly Archives: November 2012

Difference Between ArrayList and Vector

ArrayList is synchronized whereas Vector is not.Though you can add SynchronizeList to make it synchronized. (2)Both are dynamic .However while expanding the array Vector doubles,compared to ArrayList which increases the size by 50% (3)ArrayList is faster as copared to Vector … Continue reading

Posted in Java | Tagged | Leave a comment

Add all the numbers of array using Java

import java.util.ArrayList;   public class arrayutiltest { public static void main(String cp[]) { ArrayList<String> a1=new ArrayList(); ArrayList<Integer>a2=new ArrayList(); a2.add(4); a2.add(1); a2.add(4); a2.add(4); int sum=0; for(int i1=0;i1<a2.size();i1++) { sum =sum+a2.get(i1); } System.out.println(“Sum is “+sum); } }

Posted in Java | Tagged , | Leave a comment

Test Palindrome String in Java

  public class palidrometest { public void testpalidrome(String str) { StringBuffer sb=new StringBuffer(str); if(str.equals(sb.reverse().toString())) { System.out.println(str+”is a palindrome”); } else { System.out.println(str+”is not a palindrome”); } } public static void main(String args[]) { palidrometest p1=new palidrometest(); p1.testpalidrome(“ATOYOTA”); } }

Posted in Java | Tagged | Leave a comment

Queues in Java

import java.util.Iterator; import java.util.LinkedList; import java.util.Queue;   public class queuetest { public void testqueue() { Queue<Integer>q=new LinkedList<Integer>(); for(int i=1;i<10;i++) { q.add(i); } Iterator itr=q.iterator(); for(int i1:q) { System.out.println(“Elements of q are”+i1); } for(int i=1;i<10;i++) { q.remove(i); } System.out.println(“Now the elements … Continue reading

Posted in Java | Tagged | 1 Comment