Explain StringBuffers and StringTokenizers?

Showing Answers 1 - 4 of 4 Answers

Anuj Kumar Ratra

  • Feb 25th, 2006
 

The string tokenizer class allows an application to break a string into tokens. The token value or delimiter can be  specified as an argument in the constructor. Default value of the delimiter is space. This is a legacy class whose use in not encouraged now(use string.split instead). Eg

StringTokenizer st = new StringTokenizer("String tokenizer test");
     while (st.hasMoreTokens()) {
         System.out.println(st.nextToken());
     }
Output:

String

tokenizer

test

String buffer is the modifiable version of string class. String buffer objects values can be changed i.e they are normal mutable objects.

  Was this answer useful?  Yes

san_joo

  • Feb 26th, 2006
 

StringTokenizer class can be used to break a string into various parts seprated by some common value.

For example

String str="some:value:in:string";

StringTokenizer st=new StringTokenizer(str,':');

while(st.hasMoreTokens)

{

System.out.println(st.nextToken());

}

will Return :

some

value

in

string

Where as StringBuffer  class is modified version of String class, we can say it is better version of String class. String class itself uses StringBuffer class for various operations like concatination etc, Moreover the StringBuffer class is a mutable class, i.e. the values can be changed.

  Was this answer useful?  Yes

nagan

  • Apr 6th, 2006
 

StringBuffer is a class it comes with a default buffer all string manipulation are done in this buffer only.StringBuffer class is introduced by designers because String class is a Immutable.

StringTokenizer class is used to seperate strings into tokens as per delimeters.

  Was this answer useful?  Yes

soorma

  • Apr 22nd, 2006
 

String Buffer is peer class of String which provide much of the functionality of strings.

  "String represent fixed length immutable character sequences" Where as "String Buffer Represent grow able and writeable character sequences"

 all string manipulation are done in this buffer only.

 

 Constructors

 

-- StringBuffer()

-- StringBuffer(int size)

-- StringBuffer(String s)

 

StringTokenizer class is used to seperate strings into sets of tokens(parts as per delimeters) which in certain sequence convey a semantic meaning

 this class implemtns Enumeration interface so that we can Enumerate string tokens

 "Delimiters are characters which separate the tokens default set of delimiters is whitespace,tab,newline, carriage return

 

Constructors

String Tokenizer(String s)

String Tokenizer(String s,String delimeters)

String Tokenizer(String s,String delimeters,Boolean delim as Token)

 

riteshyadav14@rediffmail.com

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions