Found 7442 Articles for Java

Java program to implement binary search on char array

Anvi Jain
Updated on 29-Sep-2024 02:49:49

1K+ Views

In this article, we will learn to implement binary search on char array using Java. The binary search on a char array can be implemented by using the Arrays.binarySearch() method of java.util package. 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 be inserted into the array. Problem Statement Write a program in Java to implement binary search on char array Input 'b', 's', 'l', 'e', 'm' Output The sorted array is: b ... Read More

Long style format for Date with Java MessageFormat class

Smita Kapse
Updated on 26-Jun-2020 07:31:20

284 Views

To format message with long style format of date in Java, we use the MessageFormat class and the Date class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. ... Read More

Format a message with date in Java

Krantik Chavan
Updated on 26-Jun-2020 07:32:31

744 Views

To format the message with date in Java, we use the MessageFormat class and the Date class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration - The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder ... Read More

Format percentage with MessageFormat class in Java

Smita Kapse
Updated on 29-Jun-2020 06:16:08

250 Views

To format message with percentage fillers in Java, we use the MessageFormat class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration - The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe  MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder in {} curly ... Read More

How to format message with integer fillers in Java

Chandu yadav
Updated on 26-Jun-2020 08:09:10

384 Views

To format message with integer fillers in Java, we use the MessageFormat class. The MessageFormat class gives us a way to produce concatenated messages which are not dependent on the language. The MessageFormat class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder in {} curly ... Read More

Substitute tokens in a String in Java

George John
Updated on 26-Jun-2020 09:10:28

1K+ Views

To substitute tokens in a String in Java, we use the Message Format class. The Message Format class provides a means to produce concatenated messages which are not dependent on the language. The Message Format class extends the Serializable and Cloneable interfaces.Declaration − The java.text.MessageFormat class is declared as follows −public class MessageFormat extends FormatThe MessageFormat.format(pattern, params) method formats the message and fills in the missing parts using the objects in the params array matching up the argument numbers and the array indices.The format method has two arguments, a pattern and an array of arguments. The pattern contains placeholder in ... Read More

Set the base time zone offset to GMT in Java

Ankith Reddy
Updated on 26-Jun-2020 09:11:08

1K+ Views

In order to set the base time zone to GMT in Java, we use the setRawOffset(int offsetMillis) method. The java.util.TimeZone.setRawOffset(int offsetMillis) method set the base timezone offset to GMT.Declaration − The java.util.TimeZone.setRawOffset(int offsetMillis) method is declared as follows −public abstract void setRawOffset(int offsetMillis)where offsetMillis is the given base time zone offset to GMT.Let us set the base timezone offset to GMT in Java −Example Live Demoimport java.util.*; public class Example {    public static void main( String args[] ) {       // creating default object of TimeZone       TimeZone obj = TimeZone.getDefault();       System.out.println("Default timezone ... Read More

Get the ID of this timezone in Java

Revathi Satya Kondra
Updated on 14-Jan-2025 03:34:12

5K+ Views

To get the ID of the current timezone in Java, we use the ZoneId class that belongs to java.time package. This provides a way to work with different timezones and their IDs. In Java, the ZoneId class represents a time zone identifier, such as India/Europe. The ZoneId can be used to retrieve the unique ID of the current timezone. To Get the ID of this timezone in Java is quite easy. Let's learn the following methods: Using Zone Id Class Using Zone Id.systemDefault() Using TimeZone.getDefault().toZoneId() Using ... Read More

Get the default Time Zone in Java

Chandu yadav
Updated on 26-Jun-2020 09:13:13

2K+ Views

In order to get the default Time Zone in Java, we use the getDefault() method. The java.util.TimeZone.getDefault() method returns the default TimeZone for the particular host. The source of the default TimeZone varies with the implementation.Declaration −The java.util.TimeZone.getDefault() method is declared as follows −public static TimeZone getDefault()Let us see a program to get the default time zone in Java −Example Live Demoimport java.util.*; public class Example {    public static void main( String args[] ) {       // creating default object of TimeZone       TimeZone obj = TimeZone.getDefault();       System.out.println("Default timezone object: " + obj); ... Read More

Get the IDs according to the given time zone offset in Java

George John
Updated on 26-Jun-2020 09:14:08

241 Views

In order to get the IDs according to the given time zone offset in Java, we use the getAvailableIDs(int rawOffset) method. The java.util.TimeZone.getAvailableIDs(int rawOffset) method returns the available IDs according to the given time zone offset in the arguments.Declaration − The java.util.TimeZone.getAvailableIDs(int rawOffset) method is declared as follows −public static String[] getAvailableIDs(int rawOffset)where rawOffset is the given time zone GMT offset.Let us see a Java program which gets the IDs according to the given time zone offset −Example Live Demoimport java.util.*; public class Example {    public static void main(String args[]) {       // getting available supported ids for ... Read More

Advertisements