Java General

String to Date Java

After converting Date to String, let us see the other way of converting String to Date. The same java.text.SimpleDateFormat class used in Date to String is used here. Following code on String to Date explains. import java.util.Date; import java.text.SimpleDateFormat; import java.text.ParseException; public class StringDate { public static void main(String args[]) { try { // take …

String to Date Java Read More »

contentEquals Java

Use equals() to compare two strings but to compare a string with StringBuffer use contentEquals (). Following both are the methods of String class returning boolean values. public boolean contentEquals(java.lang.StringBuffer); public boolean contentEquals(java.lang.CharSequence); The next code explains contentEquals Java . public class Demo { public static void main(String args[]) { String str1 = “hello”; String …

contentEquals Java Read More »

DataOutputStream New Line Java

General new line character is discussed in Java New Line. Infact, new line character is operating system dependent. To know the new line character supported by the OS, use line.separator of getProperty() defined in System class as follows. String newLine = System.getProperty(“line.separator”); The above newLine string object can be used in programming to give new …

DataOutputStream New Line Java Read More »

int to Binary Octal Hexa Java

int to Binary Octal Hexa: Sometimes, it may be necessary to convert a decimal value into binary or octal or hexadecimal notation. Java comes with predefined methods to do the job with two styles. Following methods are defined in java.lang.Integer class. public static java.lang.String toString(int, int) : converts first parameter int to second parameter int. …

int to Binary Octal Hexa Java Read More »