answersLogoWhite

0


Best Answer

As of Java 1.6 it has 3:

StringTokenizer(String str)

StringTokenizer(String str, String delim)

StringTokenizer(String str, String delim, boolean returnDelims)

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How many constructors does the StringTokenizer class have?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

What is stringtokenizor in java?

StringTokenizer is a class in Java that allows you to iterate through a String's tokens, or parts that resemble a defined pattern. By default, StringTokenizer uses "\t\n\r\f" (whitespace) to break up a String. You can override this in the constructor for your own pattern. These days, the split method of String is used instead of StringTokenizer. 2 examples below: StringTokenizer st = new StringTokenizer("Hello World"); System.out.println(st.countTokens()); //2 System.out.println(st.nextElement()); //Hello System.out.println(st.nextElement()); //World StringTokenizer st = new StringTokenizer("Hello,World","[aeiou]"); System.out.println(st.countTokens()); //4 while(st.hasMoreElements()) System.out.print(st.nextElement()); //Hll,Wrld


How many constructors does class Exception have?

The Exception class has 4 constructors. They are: a. Exception() b. Exception(String arg) c. Exception(String arg, Throwable arg1) d. Exception(Throwable arg)


How can you identify a constructor from among any other methods in a class?

Constructors have the same identifier as that of the class, so if the name of your class is Book then your constructor must also be named Book. Constructors have no return type, not even void.


How many constructors can c have?

A class can have any number of constructors, as far as they are having different parameters or different number of parameters. For example, a class A can have following constructors & even more: A() -the default constructor A(A objectA) -the copy constructor A(int p) A(int p1, int p2) A(int[] p1, float p2) A(double p1, double p2, int p3) A(A objA, int[] p) A(B objB)


What is the difference between default constructor and parameterized constructor?

A default constructor is one that has no parameters (C++ also calls constructors with all default parameters a default constructor), while a parameterized constructor is one that has at least one parameter without a default value. Default constructors can be provided by the compiler if no other constructors are defined for that class or any class the class inherits from, while parameterized constructors must always be defined by the developer.

Related questions

What is stringtokenizor in java?

StringTokenizer is a class in Java that allows you to iterate through a String's tokens, or parts that resemble a defined pattern. By default, StringTokenizer uses "\t\n\r\f" (whitespace) to break up a String. You can override this in the constructor for your own pattern. These days, the split method of String is used instead of StringTokenizer. 2 examples below: StringTokenizer st = new StringTokenizer("Hello World"); System.out.println(st.countTokens()); //2 System.out.println(st.nextElement()); //Hello System.out.println(st.nextElement()); //World StringTokenizer st = new StringTokenizer("Hello,World","[aeiou]"); System.out.println(st.countTokens()); //4 while(st.hasMoreElements()) System.out.print(st.nextElement()); //Hll,Wrld


For what purpose constructors are used in Java?

Constructors are used to create the instance of a class.


How many constructors does class Exception have?

The Exception class has 4 constructors. They are: a. Exception() b. Exception(String arg) c. Exception(String arg, Throwable arg1) d. Exception(Throwable arg)


How can you identify a constructor from among any other methods in a class?

Constructors have the same identifier as that of the class, so if the name of your class is Book then your constructor must also be named Book. Constructors have no return type, not even void.


How many constructors can c have?

A class can have any number of constructors, as far as they are having different parameters or different number of parameters. For example, a class A can have following constructors & even more: A() -the default constructor A(A objectA) -the copy constructor A(int p) A(int p1, int p2) A(int[] p1, float p2) A(double p1, double p2, int p3) A(A objA, int[] p) A(B objB)


What are different type of constructor in java?

Every class, including abstract classes, MUST have a constructor. The different types are: a. Regular constructors b. Overloaded constructors and c. Private constructors


Why you use constructors?

To create an instance of the class that implementing that constructor


What is main advantage of using constructors in java?

Constructors have the same name as the class itself and they do not specify a return type, not even void because they return the instance of the class itself. Because constructors have the same name as the class then they allow method overloading and also save memory and execution time of program. Program release memory of constructors function after using this function and it reduce program complexity.


What is the difference between default constructor and parameterized constructor?

A default constructor is one that has no parameters (C++ also calls constructors with all default parameters a default constructor), while a parameterized constructor is one that has at least one parameter without a default value. Default constructors can be provided by the compiler if no other constructors are defined for that class or any class the class inherits from, while parameterized constructors must always be defined by the developer.


How many constructors may be defined for a class?

As many as are required for the class to function. All classes other than static classes require at least one constructor. Most classes will also provide copy and move constructors (with corresponding copy and move assignment operators). Additional constructors are usually provided to increase the flexibility of the class, allowing users a variety of ways to initialise objects of the class. Constructors that accept just one argument (excluding the copy and move constructors) are regarded as being conversion constructors because, from a user's perspective, they effectively convert their argument into an object of the class. Although there is effectively no limit to the number of constructors you can define, do keep in mind the mantra that simple concepts should be expressed simply and no simpler. Make good and proper use of inline initialisation, default arguments and delegation. Use explicit constructors to avoid narrowing issues and implicit conversions where narrowing is acceptable. Also, make good use of RAII (resource acquisition is initialisation) to ensure proper cleanup should any member fail to initialise during construction. For efficiency, perform as much initialisation as possible outside the body of the constructor. Ideally, the constructor body should contain no code at all.


Write a Java Program that reads a line of integers and then displays each integer and the sum of all the integers Use StringTokenizer class of javautil?

// Get input BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); String input = in.readLine(); in.close(); // Parse input int sum = 0; StringTokenizer parser = new StringTokenizer(input); while (parser.hasMoreTokens()) { int currentInt = Integer.parseInt(parser.nextToken()); System.out.println(currentInt); sum += currentInt; } System.out.println("sum = " + sum);


What is different between constructor and method?

Constructors have no return type and their names must exactly match the class name. Apart from this constructors and methods are similar to one another.