- 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 34492 Articles for Programming
![karthikeya Boyini](https://www.tutorialspoint.com/assets/profiles/13518/profile/60_31598-1537784993.jpg)
12K+ Views
To move an element from one position to other (swap) you need to –Create a temp variable and assign the value of the original position to it.Now, assign the value in the new position to original position.Finally, assign the value in the temp to the new position.ExampleLive Demoimport java.util.Arrays; public class ChangingPositions { public static void main(String args[]) { int originalPosition = 1; int newPosition = 4; int [] myArray = {23, 93, 56, 92, 39}; int temp = myArray[originalPosition]; myArray[originalPosition] = myArray[newPosition]; myArray[newPosition] = temp; System.out.println(Arrays.toString(myArray)); } }Output[23, 39, 56, 92, 93]
![Nikitha N](https://www.tutorialspoint.com/assets/profiles/13558/profile/60_76068-1512713229.jpg)
687 Views
The Arrays class of the java.util package provides toString() methods for all primitive data types and object. These methods accept an array and return its string representation.Therefore, to convert an array to string pass the required array to this method.ExampleLive Demoimport java.util.Arrays; public class ArrayToString { public static void main(String args[]) throws Exception { int[] myArray = {23, 93, 56, 92, 39}; String str = Arrays.toString(myArray); System.out.println(str); } }Output[23, 93, 56, 92, 39]
![Priya Pallavi](https://www.tutorialspoint.com/assets/profiles/13562/profile/60_91320-1512544134.jpg)
18K+ Views
Java provides ImageIO class for reading and writing an image. To convert an image to a byte array –Read the image using the read() method of the ImageIO class.Create a ByteArrayOutputStream object.Write the image to the ByteArrayOutputStream object created above using the write() method of the ImageIO class.Finally convert the contents of the ByteArrayOutputStream to a byte array using the toByteArray() method.Exampleimport java.io.ByteArrayOutputStream; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; public class ImageToByteArray { public static void main(String args[]) throws Exception{ BufferedImage bImage = ImageIO.read(new File("sample.jpg")); ... Read More
![Sharon Christine](https://www.tutorialspoint.com/assets/profiles/13517/profile/60_82215-1512649681.jpg)
2K+ Views
To move an element from one position to other (swap) you need to –Create a temp variable and assign the value of the original position to it.Now, assign the value in the new position to original position.Finally, assign the value in the temp to the new position.ExampleLive Demoimport java.util.Arrays; public class ChangingPositions { public static void main(String args[]) { int originalPosition = 1; int newPosition = 1; int [] myArray = {23, 93, 56, 92, 39}; int temp = myArray[originalPosition]; myArray[originalPosition] = myArray[newPosition]; myArray[newPosition] = temp; System.out.println(Arrays.toString(myArray)); } }Output[23, 39, 56, 92, 93]
![V Jyothi](https://www.tutorialspoint.com/assets/profiles/13530/profile/60_77592-1512648869.jpg)
18K+ Views
Java provides ImageIO class for reading and writing an image. To convert a byte array to an image.Create a ByteArrayInputStream object by passing the byte array (that is to be converted) to its constructor.Read the image using the read() method of the ImageIO class (by passing the ByteArrayInputStream objects to it as a parameter).Finally, Write the image to using the write() method of the ImageIo class.Exampleimport java.io.ByteArrayOutputStream; import java.awt.image.BufferedImage; import java.io.File; import javax.imageio.ImageIO; public class ByteArrayToImage { public static void main(String args[]) throws Exception { BufferedImage bImage = ImageIO.read(new File("sample.jpg")); ... Read More
![Sravani S](https://www.tutorialspoint.com/assets/profiles/13538/profile/60_67753-1512711355.jpg)
7K+ Views
You can read data from a PDF file using the read() method of the FileInputStream class this method requires a byte array as a parameter.Exampleimport java.io.File; import java.io.FileInputStream; import java.io.ByteArrayOutputStream; public class PdfToByteArray { public static void main(String args[]) throws Exception { File file = new File("sample.pdf"); FileInputStream fis = new FileInputStream(file); byte [] data = new byte[(int)file.length()]; fis.read(data); ByteArrayOutputStream bos = new ByteArrayOutputStream(); data = bos.toByteArray(); } }Sample.pdf
![Ramu Prasad](https://www.tutorialspoint.com/assets/profiles/13539/profile/60_87996-1512650215.jpg)
176 Views
Apache Commons provides a library named org.apache.commons.lang3 and, following is the maven dependency to add the library to your project. org.apache.commons commons-lang3 3.0 This package provides a class named ArrayUtils. Using the toPrimitive() method of this class you can convert An object array to an array of primitive types:Exampleimport java.util.Arrays; import org.apache.commons.lang3.ArrayUtils; public class ArraysToPrimitives { public static void main(String args[]) { Integer[] myArray = {234, 76, 890, 27, 10, 63}; int[] primitiveArray = ArrayUtils.toPrimitive(myArray); System.out.println(Arrays.toString(primitiveArray)); } }Output[234, 76, 890, 27, 10, 63]
4K+ Views
SSH (secure shell) is helpful for remotely managing computers in a secure manner. To connect to a server, you typically use PuTTy, MobaXTerm, or the command-line ssh application. Every Unix, Linux, and Mac server includes SSH as standard equipment, and it is usable in every data centre. SSH connections have made it feasible for secure remote access to resources, remote command execution, the transmission of software patches and updates, and other administrative or management tasks. SSH is used in systems administration and file transfer software, as well as to handle routers, server hardware, virtualization platforms, and operating systems (OSes). Additionally, ... Read More
![Govinda Sai](https://www.tutorialspoint.com/assets/profiles/13542/profile/60_86497-1512650655.jpg)
9K+ Views
A 2d array is an array of one dimensional arrays to read the contents of a file to a 2d array –Instantiate Scanner or other relevant class to read data from a file. Create an array to store the contents.To copy contents, you need two loops one nested within the other. the outer loop is to traverse through the array of one dimensional arrays and, the inner loop is to traverse through the elements of a particular one dimensional array.Create an outer loop starting from 0 up to the length of the array. Within this loop read each line trim and ... Read More
![Abhinaya](https://www.tutorialspoint.com/assets/profiles/13548/profile/60_54851-1512705920.jpg)
13K+ Views
Using the copyOfRange() method you can copy an array within a range. This method accepts three parameters, an array that you want to copy, start and end indexes of the range.You split an array using this method by copying the array ranging from 0 to length/2 to one array and length/2 to length to other.Exampleimport java.util.Arrays; import java.util.Scanner; public class SplittingAnArray { public static void main(String args[]) { Scanner s =new Scanner(System.in); System.out.println("Enter the required size of the array ::"); int size = s.nextInt(); int [] myArray ... Read More