Found 34488 Articles for Programming

Java program to remove items from Set

karthikeya Boyini
Updated on 26-Jun-2020 07:09:04

2K+ Views

A set in Java is modelled after the mathematical set and it cannot contain duplicate elements. The set interface contains the methods that are inherited from Collection. The method remove() removes the specified items from the set collection.A program that demonstrates the removal of items from Set using remove() is given as follows −Example Live Demoimport java.util.*; public class Example {    public static void main(String args[]) {       int arr[] = {5, 10, 10, 20, 30, 70, 89, 10, 111, 115};       Set set = new HashSet();       try {         ... Read More

Java Program to convert a Primitive Type Value to a String

Samual Sam
Updated on 26-Jun-2020 06:23:50

2K+ Views

For converting a primitive type value to a string in Java, use the valueOf() method.Let’s say we want to convert the following double primitive to string.double val4 = 8.34D;For that, use the valueOf() method. It converts it into a string.String str4 = String.valueOf(val4);Example Live Demopublic class Demo {    public static void main(String[] args) {       int val1 = 5;       char val2 = 'z';       float val3 = 9.56F;       double val4 = 8.34D;       System.out.println("Integer: "+val1);       System.out.println("Character: "+val2);       System.out.println("Float: "+val3);       ... Read More

Convert Char array to String in Java

karthikeya Boyini
Updated on 26-Jun-2020 06:24:54

589 Views

The valueOf() method is used in Java to convert char array to string.Here is our char array.// char array char[] c = {'p','q','r','s','t','u','v'};To convert it to string, use the valueOf() method.String str = String.valueOf(c);Example Live Demopublic class Demo {    public static void main(String[] args) {       // char array       char[] c = {'p','q','r','s','t','u','v'};       // converting to string       String str = String.valueOf(c);       System.out.println("String: "+str);    } }OutputString: pqrstuv

Python Parser for command line options

Chandu yadav
Updated on 26-Jun-2020 06:27:19

845 Views

Very often we need to pass arguments to Python script when executing from command line. However, the script raises exception when parameters needed are not provided in equal number or type or order. That’s where the need to properly parse the command line argument occurs.The argparse module provides tools for writing very easy to use command line interfaces. It handles how to parse the arguments collected in sys.argv list, automatically generate help and issues error message when invalid options are given.First step to desing the command line interface is to set up parser object. This is done by ArgumentParser() function ... Read More

Convert short to String in Java

Samual Sam
Updated on 26-Jun-2020 06:28:00

4K+ Views

The valueOf() method is used in Java to convert short to string.Let’s say we have the following short value.short val = 20;Converting the above short value to string.String.valueOf(val);Example Live Demopublic class Demo {    public static void main(String[] args) {       short shortVal = 55;       // converting short to String       String str = String.valueOf(shortVal);       System.out.println("String: "+str);    } }OutputString: 55

Support for line-oriented command interpreters in Python

Ankith Reddy
Updated on 26-Jun-2020 06:29:29

355 Views

The cmd module contains only one class called Cmd. This is used as base class for a user defined framework for line oriented command line interpreters.CmdAn object of this class or its subclass provides the line oriented interpreter framework. Important methods of this class inherited by the subclass are listed below.cmdloop()This method sends the object in a loop, accepts inputs and sends the same to appropriate command handler method in the class.As the loop starts an introductory message (give as parameter to cmdloop() method) will be displayed with a default (cmd) prompt which may be customized by prompt attribute.The interpreter ... Read More

Java Program to convert float to String

Samual Sam
Updated on 26-Jun-2020 06:30:12

211 Views

The valueOf() method is used in Java to convert float to string.Let’s say we have the following float value.float val = 10.18465F;Converting the above float value to string.String.valueOf(val);Example Live Demopublic class Demo {    public static void main(String[] args) {       float val = 98.18465F;       // converting float to String       String str = String.valueOf(val);       System.out.println("String: "+str);    } }OutputString: 98.18465

Python getpass Module

Arjun Thakur
Updated on 26-Jun-2020 06:31:13

1K+ Views

There are two functions defined in getpass module of Python’s standard library. They are useful whenever a terminal based application needs to be executed only after validating user credentials.getpass()This function prompts the user to enter a password. By default the keys entered by user in the terminal are not echoed. Also the default prompt that appears on terminal is ‘password’ which can be customized by providing a string as parameter.In following example, Python prompt is invoked from Command prompt terminal on Windows. The password entered is not echoed in the terminal.C:\python36>python Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 ... Read More

Keywords in Java

Samual Sam
Updated on 26-Jun-2020 07:04:17

663 Views

Keywords in Java are reserved words that represent predefined actions, internal processes etc. Because of this, keywords cannot be used as names of variables, functions, objects etc.The main difference between keywords and identifiers is that keywords are reserved words that represent predefined actions while identifiers are the names of variables, functions, objects etc.Some of the keywords in the Java are given as follows −abstractassertbooleanbreakbytecasecatchcharclassconstcontinuedefaultdodoubleelseenumextendsfinalfinallyfloatforgotoifimplementsimportinstanceofintinterfacelongnativenewpackageprivateprotectedpublicreturnshortstaticstrictfpsuperswitchsynchronizedthisthrowthrowstransienttryvoidvolatilewhileA program that demonstrates keywords is given as follows −Example Live Demopublic class Example { public static void main(String[] args) { int i = 5; char c = 'A'; System.out.println("i = " + i); System.out.println("c = " + ... Read More

Work with ZIP archives in Python (zipfile)

George John
Updated on 25-Jun-2020 14:25:59

798 Views

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

Advertisements