A string can be divided into tokens using Java’s StringTokenizer class. Internally, a StringTokenizer object keeps track of where it is in the string that has to be tokenized. Some procedures move this place ahead of the currently processed characters. By extracting a substring from the string that was used to generate the StringTokenizer object, a token is returned. It offers the initial stage of the parsing procedure, often known as the lexer or scanner. The String Tokenizer class enables applications to tokenize strings. The Enumeration interface is implemented by it. Data parsing is done using this class. We must specify an input string and a string with delimiters to use the String Tokenizer class The characters that divide tokens are known as delimiters. The delimiter string’s characters are all accepted as delimiters. Whitespaces, new lines, spaces, and tabs are the default delimiters. Constructors of StringToken: Let us consider ‘str’ as the string to be tokenized StringTokenizer(String str): Delimiters that are typically used include newline, space, tab, carriage return, and form […]
June 18, 2022 | Java | No comments
The Java class StringBuilder represents a mutable string of characters. The StringBuilder class offers a substitute for the String Class in Java since it constructs a mutable sequence of characters instead of an immutable one as the String Class does. The functions of the StringBuilder and StringBuffer classes are extremely similar because both create changeable […]
June 17, 2022 | Java | No comments
StringBuffer is a String peer class that provides a lot of the same functionality as strings. StringBuffer represents growable and writable character sequences, whereas a string represents fixed-length, immutable character sequences. Characters and substrings can be inserted in the middle or appended to the end of a StringBuffer. Constructors of StringBuffer class : 1. StringBuffer(): It saves […]
June 16, 2022 | Java | No comments
The methods listed below are some of the most frequently used String class methods in Java. charAt() method: The charAt() function in a string returns the character at the specified index. Output: equalsIgnoreCase() method: equalsIgnoreCase() checks for equality between two Strings while ignoring their case. Output: indexOf() method: The index of the first occurrence […]
June 15, 2022 | Java | No comments
Many useful methods for performing operations on a sequence of char values are available in the java.lang.String class. No. Method Description 1 char charAt(int index) It returns the char value for the given index. 2 int length() It returns the string length. 3 static String format(String format, Object… args) It returns a formatted string. 4 […]
June 11, 2022 | Java | No comments
Strings are Objects in Java that are internally backed by a char array. They are immutable because arrays are immutable (they can’t grow). Every time you make a change to a String, a new String is created. An array of characters functions similarly to a Java string. Consider the following scenario: is the same as: […]
June 11, 2022 | Java | No comments
Following are the important differences between an abstract class and a concrete class. Sr. No. Key Abstract Class Concrete Class 1 Supported Methods Both abstract and concrete methods can be found in an abstract class. Only concrete methods are allowed in a concrete class. The class is abstract, even if it only has one abstract […]
June 11, 2022 | Java | No comments
Comparison between a normal or regular class and a static nested class. S.NO Normal/Regular inner class Static nested class 1. Without an outer class object existing, there cannot be an inner class object. That is, the inner class object is always associated with the outer class object. There may be a static nested class object […]
June 11, 2022 | Java | No comments
It is possible to define a class within another class in Java, and these classes are referred to as nested classes. They allow you to logically group classes that are only used in one place, increasing encapsulation and making code more readable and maintainable. Syntax: Note: The scope of the enclosing class limits a nested […]
June 11, 2022 | Java | No comments
As we all know, abstraction refers to hiding the internal implementation of a feature and only giving the users the functionality. i.e. how it works (showing), what it does (showing) (hiding). Because an abstraction is achieved using both abstract classes and interfaces, Interface and Abstract classes are needed prerequisites. Let’s see the differences between them. […]
June 3, 2022 | Java | No comments