In order to reverse order of all elements of ArrayList with Java Collections, we use the Collections.reverse() method.Declaration −The java.util.Collections.reverse method is declared as follows −public static void reverse(List list)Let us see a program to reverse order of all elements of ArrayList with Java Collections −Example Live Demoimport java.util.*; public class Example { public static void main (String[] args) { ArrayList list = new ArrayList(); list.add(1); list.add(2); list.add(7); list.add(8); list.add(3); list.add(9); System.out.println("Original list : " + ... Read More
We can use Files.move() API to move file from one directory to another. Following is the syntax of the move method.public static Path move(Path source, Path target, CopyOption... options) throws IOExceptionWheresource − Source path of file to be movedtarget − Target path of file to be movedoptions − options like REPLACE_EXISTING, ATOMIC_MOVEExampleimport java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; public class Tester { public static void main(String[] args) { //move file from D:/temp/test.txt to D:/temp1/test.txt //make sure that temp1 folder exists moveFile("D:/temp/test.txt", "D:/temp1/test.txt"); } private static void moveFile(String ... Read More
In order to shuffle elements of ArrayList with Java Collections, we use the Collections.shuffle() method. The java.util.Collections.shuffle() method randomly permutes the list using a default source of randomness.Declaration −The java.util.Collections.shuffle() method is declared as follows −public static void shuffle(List list)Let us see a program to shuffle elements of ArrayList with Java Collections −Example Live Demoimport java.util.*; public class Example { public static void main (String[] args) { ArrayList list = new ArrayList(); list.add(1); list.add(2); list.add(7); list.add(8); list.add(3); list.add(9); ... Read More
Java is a multi-threaded programming language which means we can develop multi-threaded program using Java. A multi-threaded program contains two or more parts that can run concurrently and each part can handle a different task at the same time making optimal use of the available resources specially when your computer has multiple CPUs.By definition, multitasking is when multiple processes share common processing resources such as a CPU. Multi-threading extends the idea of multitasking into applications where you can subdivide specific operations within a single application into individual threads. Each of the threads can run in parallel. The OS divides processing ... Read More
In order to swap elements of ArrayList with Java collections, we need to use the Collections.swap() method. It swaps the elements at the specified positions in the list.Declaration −The java.util.Collections.swap() method is declared as follows −public static void swap(List list, int i, int j)where i is the index of the first element to be swapped, j is the index of the other element to be swapped and list is the list where the swapping takes place.Let us see a program to swap elements of ArrayList with Java collections −Example Live Demoimport java.util.*; public class Example { public static void ... Read More
Automation is an integral part of the development and progression of equipment and processes that in turn, are integral parts of most of the activities that act as engines of growth across most economies around the world. There's another side to automation and that is the importance of its application in military equipment and processes. It has been seen that nations with a history of producing robust and highly efficient military equipment, are the ones that are dominating the automation industry today.The USA, Germany, Japan, France, UK, Russia, Sweden, Italy, and Canada among a few others dominate in automation excellence.The ... Read More
Use the border-top-right radius property in CSS to set the top right radius border. You can try to run the following code to implement border-top-right-radius property −ExampleLive Demo #rcorner { border-radius: 25px; border-top-right-radius: 45px; background: orange; padding: 20px; width: 400px; height: 250px; } Rounded border-top-right corner!
In Serialization when inheritance is introduced then on the basis of superclass and subclass certain cases have been defined which make the understanding of Serialization in each case much simpler. The fundamental rules which should be followed are as below.1. When super class is implements Serializable interface and subclass is not.In this case the object of subclass get serialized by default when superclass get serialize, even if subclass doesn't implements Serializable interface.Examplepublic class TestSerialization { public static void main(String[] args) throws IOException, ClassNotFoundException { B obj = new B(); FileOutputStream fos = new ... Read More
A number of functions for hgh level operations on files and directories have been defined in shutil module of Python’s standard library.copy()This function copies a file to a specified file in same or other directory. First parameter to the function is a string representation of existing file. Second argument is either name of resultant file or directory. If it is a directory, the file is coped in it with same name. The metadata of original file is not maintained.>>> import shutil >>> shutil.copy("hello.py", "newdir/") 'newdir/hello.py'copy2()This function is similar to copy() function except for the fact that it retains metadata of ... Read More
The ZIP is one of the most popular file formats used for archiving and compression. It has been in use since the days of MSDOS and PC and has been used by famous PKZIP application.The zipfile module in Python’s standard library provides classes that facilitate the tools for creating, extracting, reading and writing to ZIP archives.ZipFile()This function returns a ZipFile object from a file parameter which can be a string or file object as created by built-in open() function. The function needs a mode parameter whose default value is ‘r’ although it can take ‘w’ or ‘a’ value for opening ... Read More