Anvi Jain has Published 634 Articles

Reverse the sequence of characters in a StringBuffer Object in Java

Anvi Jain

Anvi Jain

Updated on 26-Jun-2020 14:57:30

147 Views

In order to reverse the sequence of characters in a StringBuffer Object, we use the reverse() method. The reverse() method replaces the character sequence with the reverse of its own.Declaration − The java.lang.StringBuffer.reverse method is declared as follows−public StringBuffer reverse()Let us see a program to reverse the sequence of characters ... Read More

Convert String to UTF-8 bytes in Java

Anvi Jain

Anvi Jain

Updated on 26-Jun-2020 13:45:42

20K+ Views

Before converting a String to UTF-8-bytes, let us have a look at UTF-8.UTF-8 is a variable width character encoding. UTF-8 has ability to be as condense as ASCII but can also contain any unicode characters with some increase in the size of the file. UTF stands for Unicode Transformation Format. ... Read More

Get the absolute value of float, int, double and long in Java

Anvi Jain

Anvi Jain

Updated on 26-Jun-2020 13:25:43

753 Views

The java.lang.Math class has an abs() method which facilitates us to find the absolute values of different data types.Absolute value of floatIn order to compute the absolute value of a float value, we use the java.lang.Math.abs(float a) method. If the argument ‘a’ is negative, the negation of ‘a’ is returned. ... Read More

Java Program to implement Binary Search on char array

Anvi Jain

Anvi Jain

Updated on 26-Jun-2020 07:30:45

584 Views

Binary search on a char array can be implemented by using the method java.util.Arrays.binarySearch(). This method returns the index of the required char element if it is available in the array, otherwise, it returns (-(insertion point) - 1) where the insertion point is the position at which the element would ... Read More

Enable Assertions from the command line in Java

Anvi Jain

Anvi Jain

Updated on 26-Jun-2020 06:46:07

379 Views

By default, assertions are disabled in Java. In order to enable them we use the following command −java -ea Example (or) java -enableassertions ExampleHere, Example is the name of the Java file.Let us see an example for generation of an assertion error by the JVM −Example Live Demopublic class Example { ... Read More

Validate the ZIP code with Java Regular expressions

Anvi Jain

Anvi Jain

Updated on 25-Jun-2020 15:04:40

333 Views

In order to match the ZIP code using regular expression, we use the matches method in Java. The java.lang.String.matches() method returns a boolean value which depends on the matching of the String with the regular expression.Declaration − The java.lang.String.matches() method is declared as follows −public boolean matches(String regex)Let us see ... Read More

Java Program to fill elements in a short array

Anvi Jain

Anvi Jain

Updated on 25-Jun-2020 14:57:59

149 Views

Elements can be filled in a short array using the java.util.Arrays.fill() method. This method assigns the required short value to the short array in Java. The two parameters required are the array name and the value that is to be stored in the array elements.A program that demonstrates this is ... Read More

Get the Component Type of an Array Object in Java

Anvi Jain

Anvi Jain

Updated on 25-Jun-2020 13:02:42

1K+ Views

In order to get the component type of an Array Object in Java, we use the getComponentType() method. The getComponentType() method returns the Class denoting the component type of an array. If the class is not an array class this method returns null.Declaration − The java.lang.Class.getComponentType() method is declared as ... Read More

How to work with getDeclaringClass() in Java

Anvi Jain

Anvi Jain

Updated on 25-Jun-2020 12:54:34

53 Views

The getDeclaringClass() method returns the Class object for the class in which the object was declared. This happens only if the Class of the Class object is a member of another class. Otherwise this method returns null.Also, if a primitive type, array class, void etc. are represented by the Class ... Read More

How to schedule tasks in Java to run for repeated fixed-rate execution, beginning at the specified time

Anvi Jain

Anvi Jain

Updated on 25-Jun-2020 12:33:59

2K+ Views

One of the methods the Timer class is void scheduleAtFixedRate(TimerTask task, Date firstTime, long period). This method schedules the specified task for repeated fixed-rate execution, beginning at the specified time.In fixed-rate execution, each execution is scheduled with respect to the scheduled run time of the initial execution. Fixed-rate execution is ... Read More

Previous 1 ... 4 5 6 7 8 ... 64 Next
Advertisements