- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Karthikeya Boyini has Published 2383 Articles
karthikeya Boyini
412 Views
To construct on string from another, firstly take a charcter array for the first string.char ch[] = { 'A', 'M', 'I', 'T' }; String str1 = new String(ch);The above forms first string. Now, let us created another string from the first string.String str2 = new String(str1);In this way, we can ... Read More
karthikeya Boyini
4K+ Views
To display number with thousands separator, set a comma flag.System.out.printf( "%, d", 78567);The above would result.78, 567Let’s check for bigger numbers.System.out.printf( "%, d", 463758);The above would result.463, 758Example Live Demopublic class Demo { public static void main( String args[] ) { System.out.printf( "%, d", 95647 ); ... Read More
karthikeya Boyini
347 Views
To display seconds since the epoch, use the ‘s’ Date and Time conversion specifier.System.out.printf("Seconds since epoch = %ts", d);The above would display seconds since.1970-01-01 00:00:00 GMTExample Live Demoimport java.util.Date; public class Demo { public static void main(String[] args) { Date d = new Date(); ... Read More
karthikeya Boyini
68 Views
Locale-specific morning/afternoon indicator is the AM/PM marker indicator.Use the ‘p’ conversion character to display AM/PM.System.out.printf("Morning/afternoon indicator: %tp", d);Example Live Demoimport java.util.Date; public class Demo { public static void main(String[] args) { Date d = new Date(); System.out.printf("Morning/afternoon indicator: %tp", d); System.out.printf("Morning/afternoon ... Read More
karthikeya Boyini
386 Views
Use the ‘c’ date conversion character to display UNIX date format in Java.System.out.printf("Unix date format: %tc", d);Above, d is a date object.Date d = new Date();Example Live Demoimport java.util.Date; import java.text.DateFormat; import java.text.SimpleDateFormat; public class Demo { public static void main(String[] args) throws Exception { Date d ... Read More
karthikeya Boyini
278 Views
Floating-point conversion characters include the following.CharacterDescription%edecimal number in computerized scientific notation%Edecimal number in computerized scientific notation%fdecimal number%gbased on computerized scientific notation or decimal format, %Gbased on computerized scientific notation or decimal format, Example Live Demopublic class Demo { public static void main(String[] args) throws Exception { System.out.printf("Integer ... Read More
karthikeya Boyini
850 Views
Let’s say we have the following string.String str = "Demo Text!";To copy some part of the above string, use the getChars() method.// copy characters from string into chArray =str.getChars( 0, 5, chArray, 0 );The following is an example to copy characters from string into char Array in Java.Example Live Demopublic class ... Read More
karthikeya Boyini
12K+ Views
The Integer.toHexString() method in Java converts Integer to hex string.Let’s say the following are our integer values.int val1 = 5; int val2 = 7; int val3 = 13;Convert the above int values to hex string.Integer.toHexString(val1); Integer.toHexString(val2); Integer.toHexString(val3);Example Live Demopublic class Demo { public static void main(String[] args) { ... Read More
karthikeya Boyini
573 Views
The Integer.toOctalString() method in Java converts int to octal string.Let’s say the following are our integer values.int val1 = 9; int val2 = 20; int val3 = 2;Convert the above int values to octal string.Integer.toOctalString(val1); Integer.toOctalString(val2); Integer.toOctalString(val3);Example Live Demopublic class Demo { public static void main(String[] args) { ... Read More
karthikeya Boyini
195 Views
Use the Short.parseShort() method in Java to convert a String to a short.Let’s say the following is our string.String str = “76”;Now, the parseShort() method will convert the string to short.byte val = Byte.parseByte(str);Example Live Demopublic class Demo { public static void main(String[] args) { String str = "76"; short val = Short.parseShort(str); System.out.println(val); ... Read More