- 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
Found 2616 Articles for Java
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
76K+ Views
Using the toCharArray() methodThe toCharArray() method of this class converts the String to a character array and returns it. To sort a string value alphabetically −Get the required string.Convert the given string to a character array using the toCharArray() method.Sort the obtained array using the sort() method of the Arrays class.Convert the sorted array to String by passing it to the constructor of the String array.Example Live Demoimport java.util.Arrays; import java.util.Scanner; public class SortingString { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter a string value: "); ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
2K+ Views
You can retrieve the contents of a collection object in three ways −Using for each loopThe foreach loop or enhanced for loop, which enables you to traverse the complete collection object sequentially.Example Live Demoimport java.util.ArrayList; public class RetrievingData { public static void main(String[] args) { ArrayList list = new ArrayList(); //Instantiating an ArrayList object list.add("JavaFX"); list.add("Java"); list.add("WebGL"); list.add("OpenCV"); list.add("OpenNLP"); list.add("JOGL"); list.add("Hadoop"); list.add("HBase"); list.add("Flume"); ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
184 Views
By adding each element of the arrayThe add() method of the ArrayList class accepts an element and adds it to the current array list. To convert an array to array list using this method −Get the string array.Create an empty ArrayList object.Add each element of the array to the ArrayList.Print the contents of the array list.Example Live Demoimport java.util.ArrayList; import java.util.Iterator; public class ArrayToArrayList { public static void main(String args[]) { String stringArray[] = {"JavaFX", "Java", "WebGL", "OpenCV", "OpenNLP", "JOGL", "Hadoop", "HBase", "Flume", "Mahout", "Impala"}; ArrayList arrayList = new ArrayList(); for(int ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
2K+ Views
The split() method of the String class accepts a String value representing the delimiter and splits into array of tokens (words), treating the string between the occurrence of two delimiters as one token.For example if you pass single space “ ” as a delimiter to this method and try to split a String. This method considers the word between two spaces as one token and returns an array of words (between spaces) in the current String.If the String does not contain the specified delimiter this method returns an array containing the whole string as element.The regular expression “\W+” matches all ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
5K+ Views
The toArray() method of the LinkedList class converts the current Linked List object into an array of object type and returns it. This array contains all of the elements in this list in proper sequence (from first to last element). This acts as bridge between array-based and collection-based APIs.Therefore, to convert a LinkedList to an array −Instantiate the LinkedList class.Populate it using the add() method.Invoke the toArray() method on the above created linked list and retrieve the object array.Convert each and every element of the object array to string.Example Live Demoimport java.util.Arrays; import java.util.LinkedList; public class LinkedListToArray { public static ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
615 Views
The ArrayList and, LinkedList classes implements the List interface of the java.util package. This interface provided two variants of the remove() method to remove particular elements as shown below −E remove(int index)boolean remove(Object o) −Using one of these methods you can delete a desired element from the List or, linkedList in Java.E remove(int index) − This method accepts an integer representing a particular position in the List object and, removes the element at the given position. If the remove operation is successful, this method returns the element that has been removed.If the index value passed to this method is less ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
441 Views
The unmodifiableList() method of the java.util.Collections class accepts an object of the List interface (object of implementing its class) and returns an unmodifiable form of the given object. The user has only read-only access to the obtained list.ExampleFollowing Java program creates an ArrayList object, adds elements to it, converts it into a read-only List object. Live Demoimport java.util.ArrayList; import java.util.Collections; import java.util.List; public class ArrayListReadOnly { public static void main(String[] args) { //Instantiating an ArrayList object ArrayList list = new ArrayList(); list.add("JavaFx"); list.add("Java"); list.add("WebGL"); ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
520 Views
RMI stands for Remote Method Invocation. It is a mechanism that allows an object residing in one system (JVM) to access/invoke an object running on another JVM.RMI is used to build distributed applications; it provides remote communication between Java programs. It is provided in the package java.rmi.To write an RMI Java application, you would have to follow the steps given below −Step1 − Define the Remote InterfaceA remote interface provides the description of all the methods of a particular remote object. The client communicates with this remote interface. Therefore, you need to create an interface that extends the predefined interface, ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
216 Views
The URL class of the java.net package represents a Uniform Resource Locator which is used to point a resource(file or, directory or a reference) in the world wide web.This class provides various constructors one of them accepts a String parameter and constructs an object of the URL class.The openStream() method of this class opens a connection to the URL represented by the current object and returns an InputStream object using which you can read data from the URL.Therefore, to read data from web page (using the URL class) −Instantiate the java.net.URL class by passing the URL of the desired web ... Read More
![Maruthi Krishna](https://www.tutorialspoint.com/assets/profiles/119958/profile/60_3780337-1641548568.png)
1K+ Views
While reading the contents of a file in certain scenarios the end of the file will be reached in such scenarios a EOFException is thrown.Especially, this exception is thrown while reading data using the Input stream objects. In other scenarios a specific value will be thrown when the end of file reached.ExampleLet us consider the DataInputStream class, it provides various methods such as readboolean(), readByte(), readChar() etc.. to read primitive values. While reading data from a file using these methods when the end of file is reached an EOFException is thrown.import java.io.DataInputStream; import java.io.FileInputStream; public class EOFExample { public ... Read More