
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7442 Articles for Java

15K+ Views
The Set object provides a method known as toArray(). This method accepts an empty array as argument, converts the current Set to an array and places in the given array. To convert a Set object to an array − Create a Set object. Add elements to it. Create an empty array with size of the created Set. Convert the Set to an array using the toArray() method, bypassing the above-created array as an argument to it. Print the contents of the array.ExampleLive Demoimport java.util.HashSet; import java.util.Set; public class SetToArray { public static void main(String args[]){ Set set = new HashSet(); ... Read More

32K+ Views
The Map class's object contains key and value pairs. You can convert it into two list objects one which contains key values and the one which contains map values separately. To convert a map to list − Create a Map object. Using the put() method insert elements to it as key, value pairs Create an ArrayList of integer type to hold the keys of the map. In its constructor call the method keySet() of the Map class. Create an ArrayList of String type to hold the values of the map. In ... Read More

32K+ Views
The Map class's object contains key and value pairs. You can convert it into two list objects one which contains key values and the one which contains map values separately. To convert a map to list − Create a Map object. Using the put() method insert elements to it as key, value pairs Create an ArrayList of integer type to hold the keys of the map. In its constructor call the method keySet() of the Map class. Create an ArrayList of String type to hold the values of the map. In ... Read More

3K+ Views
To join two given lists the addAll() method of the java.util.ArrayList class is used to insert all of the elements in the specified collection into this list. To add contents of a list to another − Problem Statement Write a program in Java to join two given lists − Input Contents of list1 ::[Apple, Orange, Banana] Contents of list2 ::[Grapes, Mango, Strawberry] Output Contents of list1 after adding list2 to it ::[Apple, Orange, Banana, Grapes, Mango, Strawberry] Steps to join two given lists Following are the steps to join two given lists − ... Read More

3K+ Views
To join two given lists the addAll() method of the java.util.ArrayList class is used to insert all of the elements in the specified collection into this list. To add contents of a list to another − Problem Statement Write a program in Java to join two given lists − Input Contents of list1 ::[Apple, Orange, Banana] Contents of list2 ::[Grapes, Mango, Strawberry] Output Contents of list1 after adding list2 to it ::[Apple, Orange, Banana, Grapes, Mango, Strawberry] Steps to join two given lists Following are the steps to join two given lists − ... Read More

19K+ Views
A List is a collection in Java that is used to store a sequence of elements. It is part of the Java Collections Framework and allows us to perform various operations on the elements, such as adding, removing, and accessing them. Converting a list to an array in Java can be done using several methods. Below are some of the common ways to achieve this: Using For Loop Using toArray() Method Using Stream API Using a For Loop We will use the for loop to iterate ... Read More

7K+ Views
The Java.io.BufferedWriter class writes text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings. To add contents to a file − Instantiate the BufferedWriter class. By passing the FileWriter object as an argument to its constructor. Write data to the file using the write() method.Exampleimport java.io.File; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.IOException; public class AppendToFileExample { public static void main( String[] args ) { try { String data = " Tutorials Point is a best website in the world"; ... Read More

7K+ Views
The Java.io.BufferedWriter class writes text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings. To add contents to a file − Instantiate the BufferedWriter class. By passing the FileWriter object as an argument to its constructor. Write data to the file using the write() method.Exampleimport java.io.File; import java.io.FileWriter; import java.io.BufferedWriter; import java.io.IOException; public class AppendToFileExample { public static void main( String[] args ) { try { String data = " Tutorials Point is a best website in the world"; ... Read More

125 Views
Following is an example to add a given time to a particular date.ProgramLive Demoimport java.util.*; public class Main { public static void main(String[] args) throws Exception { Date d1 = new Date(); Calendar cl = Calendar. getInstance(); cl.setTime(d1); System.out.println("today is " + d1.toString()); cl. add(Calendar.MONTH, 1); System.out.println("date after a month will be " + cl.getTime().toString() ); cl. add(Calendar.HOUR, 70); System.out.println("date after 7 hrs will be " + cl.getTime().toString() ); cl. add(Calendar.YEAR, ... Read More

125 Views
Following is an example to add a given time to a particular date.ProgramLive Demoimport java.util.*; public class Main { public static void main(String[] args) throws Exception { Date d1 = new Date(); Calendar cl = Calendar. getInstance(); cl.setTime(d1); System.out.println("today is " + d1.toString()); cl. add(Calendar.MONTH, 1); System.out.println("date after a month will be " + cl.getTime().toString() ); cl. add(Calendar.HOUR, 70); System.out.println("date after 7 hrs will be " + cl.getTime().toString() ); cl. add(Calendar.YEAR, ... Read More