Skip to content

Programming Articles

  • HOME
  • Python
  • JavaScript
  • C/C++
  • Java
  • Terms & Conditions and Privacy Policy
  • About US
Main Menu

Formatted Codes

Formatted Codes / Java

How to convert a String to int in Java?

Query: My String contains only numbers, and I want to return the number it represents. For example, given the string “1234” the result should be the number 1234. In this post, I’ll convert …

How to convert a String to int in Java? Learn More
Formatted Codes / Python HowTos

How to catch multiple exceptions in one line in Python?

Query explained: I know that I can do: I can also do this: But if I want to do the same thing inside two different exceptions, the best I can …

How to catch multiple exceptions in one line in Python? Learn More
Formatted Codes / JavaScript

How to get the current URL with JavaScript?

Query: All I want is to get the website URL. Not the URL as taken from a link. On the page loading, I need to be able to grab the …

How to get the current URL with JavaScript? Learn More
Formatted Codes / JavaScript

How to round off to 2 decimal places in javascript?

Sample query: I’d like to round at most 2 decimal places, but only if necessary. Input: Output: How can I do this in JavaScript? How to round off to 2 decimal …

How to round off to 2 decimal places in javascript? Learn More
Formatted Codes / JavaScript

How to check for an empty, undefined, or null string in JavaScript?

Sample query: Is there a simple string.Empty available in JavaScript, or is it just a case of checking for “”? How to check empty string in JavaScript? If you just want to check …

How to check for an empty, undefined, or null string in JavaScript? Learn More
Formatted Codes / Python HowTos

How to list all files of a directory in Python?

Query: How can I list all files of a directory in Python and add them to a list? How to list all files of a directory in Python? Method #1: os.listdir() will …

How to list all files of a directory in Python? Learn More
Formatted Codes / JavaScript

How to check if a key exists in a JavaScript object?

Query: How do I check if a particular key is present in a JavaScript object or array? If a key doesn’t exist, and I try to access it, will it …

How to check if a key exists in a JavaScript object? Learn More
C# / Formatted Codes

How to cast int to enum in C#?

Query: How can an int be cast to an enum in C#? How to cast int to enum in C#? From an int: From a string: Update: From number you can also Answer #2: …

How to cast int to enum in C#? Learn More
Formatted Codes / Java

How to iterate over a Map in Java?

Query explained: If I have an object implementing the Map interface in Java and I wish to iterate over every pair contained within it, what is the most efficient way of going …

How to iterate over a Map in Java? Learn More
Formatted Codes / Python HowTos

How to iterate over dictionaries using ‘for’ loops in Python?

Query explained: I am a bit puzzled by the following code: What I don’t understand is the key portion. How does Python recognize that it needs only to read the key from …

How to iterate over dictionaries using ‘for’ loops in Python? Learn More
Formatted Codes / Python HowTos

How to find the index of an item in a list in Python?

The following code is the solution: Caveats follow Note that while this is perhaps the cleanest way to answer the question as asked, index is a rather weak component of the list API, and I …

How to find the index of an item in a list in Python? Learn More
Formatted Codes / Java

How to create ArrayList from an array in Java?

I have an array that is initialized like: I would like to convert this array into an object of the ArrayList class. How to create ArrayList from array in Java? Short answer: …

How to create ArrayList from an array in Java? Learn More
Formatted Codes / JavaScript

How to Check if an Object is Empty in JavaScript?

Query: After an AJAX request, sometimes my application may return an empty object, like: How can I check whether that’s the case? How to Check if Object is Empty in …

How to Check if an Object is Empty in JavaScript? Learn More
DB-SQL/Postgresql/MongoDB / Formatted Codes

How to UPDATE from a SELECT in SQL Server?

In SQL Server, it is possible to insert rows into a table with an INSERT.. SELECT statement: Is it also possible to update a table with SELECT? I have a temporary table containing the values and …

How to UPDATE from a SELECT in SQL Server? Learn More
Android / Formatted Codes

How to close the Android soft keyboard programmatically? [Answered]

You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your focused view. This will force the keyboard to be …

How to close the Android soft keyboard programmatically? [Answered] Learn More
Formatted Codes / JavaScript

How to get a timestamp in JavaScript? [Answered]

Short & Snazzy: A unary operator like plus triggers the valueOf method in the Date object and it returns the timestamp (without any alteration). Details: On almost all current browsers you can use Date.now() to get the UTC …

How to get a timestamp in JavaScript? [Answered] Learn More
Formatted Codes / Java

How to convert an InputStream into a String in Java? [Answered]

Sample query: If you have a java.io.InputStream object, how should you process that object and produce a String? Suppose I have an InputStream that contains text data, and I want to convert it to a String, …

How to convert an InputStream into a String in Java? [Answered] Learn More

Posts navigation

1 2 … 8 Next

Featured Posts

From UNIX to Linux – History of Linux

21st November 202010th September 2022

Best themes for Ubuntu: Make Ubuntu Beautiful

20th October 202010th September 2022

Strings in Python

12th September 202010th September 2022

Is Python hard to learn? Top best learning resources

18th April 202010th September 2022

Recent posts

  • How to pad a string with zeroes to the left?
  • What is the difference between process and thread?
  • How to generate a random alpha-numeric string in Java?
  • How to auto-resize an image to fit a ‘div’ container?
  • How to get a Docker container’s IP address from the host?
  • How to display a JavaScript object?
Copyright © 2023 Programming Articles.
Powered by WordPress and HitMag.