Three More Questions for You


1. Why Java introduced StringBuilder with the same functionality (usage) of StringBuffer?
2. Why split() method was introduced when Java has already StringTokenizer?Ans: StringTokenizer comes with JDK1.0 version where as split() method comes with JDK1.4 version. StringTokenizer beongs to java.util package and split() is defined in String class of java.lang package. One major difference is, split() supports regular expressions but StringTokenizer does not. If tokens (independent words) are required in an array form for easy retrieval and operation, split() is preferred. No operations on elements and only retrieval, StringTokenizer is preferred. It is jsut only coding requirements.
3. Way ArrayList was introduced when Vector with similar functionality exists?
Ans: ArrayList methods are not synchronized but Vector are. For important and critical data operations, where data corruption or inconsistency should not prevail, prefer Vector and for unimportant prefer ArrayList. Vector performance is slow (as methods are synchronized) but ArrayList operations is very fast.

Leave a Comment

Your email address will not be published.