Found 26504 Articles for Server Side Programming

How to create object arrays Java? What are their disadvantages

Maruthi Krishna
Updated on 08-Feb-2021 11:15:48

179 Views

Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array.Element: Each item stored in an array is called an element.Index: Each location of an element in an array has a numerical index, which is used to identify the element.Creating object arraysYes, since objects are also considered as datatypes (reference) in Java, you can create an array of the type of a particular class and, populate ... Read More

How to get the directories (only) from a folder using Java?

Maruthi Krishna
Updated on 08-Feb-2021 11:15:36

1K+ Views

The ListFiles() method returns an array holding the objects (abstract paths) of all the files (and directories) in the path represented by the current (File) object.The File Filter interface is filter for the path names you can pass this as a parameter to the listFiles() method. This method filters the file names passed on the passed filter.To get the directories in a folder implement a FileFilter which accepts only directories and pass it as a parameter to the listFiles() method.Following is a screen shot of the contents of the ExampleDirectoryExampleimport java.io.File; import java.io.FileFilter; import java.io.IOException; public class MyExample{    public ... Read More

How to multiply matrices elements if matrices are stored in a list in R?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 11:16:14

504 Views

To multiply matrices elements if matrices are stored in a list, we can make use of Reduce function. For example, if we have four matrices named as M1, M2, M3, and M4 stored in a list object called List then the multiplication each element in all the four matrices can be done by using the command Reduce("*",List).Example1 Live DemoM1

How to set the plot area to assign the plots manually in base R?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 13:38:43

106 Views

We can split the screen to assign the plots manually in the plot area. The split.screen function can be used for this purpose. For example, if we want to create 4 plots in the plot window then we can use split.screen(c(2, 2)). Now to create the plot in first screen the command will be screen(1) then plot will be created. If we again create the plot then the original plot in screen(1) will be replaced with the new one. To create the plot in 3rd screen that is screen(3), we first need to use the command screen(3) and then create ... Read More

How to increase the X-axis length of histogram in base R?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 11:11:14

6K+ Views

To increase the X-axis length of histogram in base R, we can use the axis function. The most important thing to remember while using the axis function is mentioning the appropriate sequence based on the values in the vector or in the column of the data frame if a data frame is used.Example Live Demox

How to list all files (only) from a directory using Java?

Maruthi Krishna
Updated on 08-Feb-2021 11:13:47

3K+ Views

The ListFiles() method returns an array holding the objects (abstract paths) of all the files (and directories) in the path represented by the current (File) object.The File Filter interface is filter for the path names you can pass this as a parameter to the listFiles() method. This method filters the file names passed on the passed filter.To get the files in a folder implement a FileFilter which accepts only files and pass it as a parameter to the listFiles() method.Following is a screen shot of the contents of the ExampleDirectoryExampleimport java.io.File; import java.io.FileFilter; import java.io.IOException; public class Demo{    public ... Read More

How to read all files in a folder to a single file using Java?

Maruthi Krishna
Updated on 08-Feb-2021 11:10:12

9K+ Views

The listFiles() method of the File class returns an array holding the objects (abstract paths) of all the files (and directories) in the path represented by the current (File) object.To read the contents of all the files in a folder into a single file −Create a file object by passing the required file path as a parameter.Read the contents of each file using Scanner or any other reader.Append the read contents into a StringBuffer.Write the StringBuffer contents into the required output file.Exampleimport java.io.DataOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Scanner; public class Test {    public static void main(String ... Read More

How to create a combination of pairs from a vector in R?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 11:09:34

3K+ Views

To create a combination of pairs, we can use the combn function. This function will be helpful to use the vector length and the value 2 that represents a pair to create the combinations. Although, this is enough but we can transpose the output to get a better−looking output.Example1 Live Demox1

How to search a file in a directory in java

Maruthi Krishna
Updated on 08-Feb-2021 11:09:15

4K+ Views

The List() method of the File class returns a String array containing the names of all the files and directories in the path represented by the current (File) object.In order to search for a file you need to compare the name of each file in the directory to the name of the required file using the equals() method.ExampleLive Demoimport java.io.File; import java.util.Arrays; import java.util.Scanner; public class Example {    public static void main(String[] argv) throws Exception {       System.out.println("Enter the directory path: ");       Scanner sc = new Scanner(System.in);       String pathStr = sc.next(); ... Read More

How to check for duplicates in data.table object in R?

Nizamuddin Siddiqui
Updated on 08-Feb-2021 11:09:55

534 Views

The checking for duplicates in a data.table object can be easily done with the help of delta ($) operator that is used to access the columns and the duplicated function. For example, if a data.table object DT contains a column x then to check the duplicates in x, we can use the command duplicated(DT$x).Example1Loading data.table object and creating an object −library(data.table) set.seed(141) x

Advertisements