Programming Articles - Page 3304 of 3366

How to convert an array of objects to an array of their primitive types in java?

Ramu Prasad
Updated on 19-Feb-2020 11:04:46

320 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]

What is the simplest way to SSH using Python?

Niharikaa Aitam
Updated on 07-Jun-2025 22:28:13

6K+ Views

SSH is referred as secure shell which is useful to remotely manage computers in a secure manner. To connect to a server, we 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 ... Read More

How to read a 2d array from a file in java?

Govinda Sai
Updated on 19-Feb-2020 11:20:12

11K+ 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

How to divide an array into half in java?

Abhinaya
Updated on 19-Feb-2020 11:21:36

16K+ 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

How to perform different commands over ssh with Python?

Niharikaa Aitam
Updated on 20-Jun-2025 19:15:44

2K+ Views

When we want to remotely access and execute commands on another machine then we use the paramiko library in Python. Paramiko is a third-party library that is used to connect and communicate securely with remote machines using the SSH, i.e., Secure Shell protocol. It allows us to execute commands, transfer files, and perform other remote tasks programmatically. To use the Paramiko library, first we need to install it in our local system using the below command - pip install paramiko Example Following is the example, in which we connect to a remote server via SSH and perform multiple shell ... Read More

How to count unique elements in the array using java?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:20

1K+ Views

The interface Set does not allow duplicate elements, therefore, create a set object and try to add each element to it using the add() method in case of repetition of elements this method returns false − If you try to add all the elements of the array to a Set, it accepts only unique elements − Example import java.util.Arrays; import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class CountingUniqueElements { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.println("Enter the size ... Read More

How to use FTP in Python?

SaiKrishna Tavva
Updated on 13-Nov-2024 12:47:27

495 Views

In Python we can use FTP (File Transfer Protocol) by importing the ftplib module, it will provide a simple interface to access FTP servers to retrieve files and process them locally. ftplib module allows us to write Python programs that perform a variety of automated FTP tasks. Objectives of FTP The objectives of FTP are as follows FTP provides file sharing. FTP helps us to encourage the use of remote computers. FTP is used to transfer the data reliably and efficiently. Some Common tasks we can perform using FTP in Python by utilizing the 'ftplib' module are as follows: ... Read More

How to find numbers in an array that are greater than, less than, or equal to a value in java?

Srinivas Gorla
Updated on 16-Jun-2020 09:36:58

4K+ Views

You can find numbers in an array that are greater than, less than, or equal to a value as:ExampleLive Demopublic class GreaterOrLess {    public static void main(String args[]) {       int value = 65;       int[] myArray = {41, 52, 63, 74, 85, 96 };       System.out.println("Elements of the array that are equal to the given value are::");       for(int i = 0; i

How to store a 2d Array in another 2d Array in java?

Abhinanda Shri
Updated on 19-Feb-2020 11:22:53

3K+ Views

Create an array to which you want to store the existing array with the same length. A 2d array is an array of one dimensional arrays therefore, to copy (or, to perform any operation on) the elements of the 2d array you need two loops one nested within the other. Where, 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.Examplepublic class Copying2DArray {    public static void main(String args[]) {       int[][] myArray = {{41, 52, 63}, {74, ... Read More

How to copy a file to a remote server in Python using SCP or SSH?

Niharikaa Aitam
Updated on 20-Jun-2025 19:16:33

17K+ Views

When we want to transfer files from our local system to a remote server securely, Python provides possible ways to do the file transfer using the Paramiko and SCP libraries. These libraries support SSH-based file transfer, which is secure and reliable. Installing Required Libraries Before we start with file transfer, we need to install all the required libraries with the help of below commands - pip install paramiko scp Using paramiko and SCP/SSH Paramiko is a third-party library available in Python, which is used to transfer a file to a remote server without using an external SCP module. This ... Read More

Advertisements