Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 2419 of 3366
432 Views
In this section we will see how to sort numbers according to their sum of digits. So if a number has lesser sum of digits, then that will be placed at first, then next number will be placed with larger sum of digits.data = {14, 129, 501, 23, 0, 145}after sorting, they will be −data = {0, 14, 23, 501, 145, 129}Here we will create our own comparison logic to sort them. That comparison logic will be used in the sort function in C++ STL.Algorithmcompare(num1, num2): Begin if sum of digits of num1 < sum of digits of num2, ... Read More
1K+ Views
Here we will see how to sort a list of strings based on their lengths. So if a string has less number of characters, then that will be placed first, then other longer strings will be placed. Suppose the strings arestr_list = {“Hello”, “ABC”, “Programming”, “Length”, “Population”}after sorting, they will be −str_list = {“ABC”, “Hello”, “Length”, “Population”, “Programming”}Here we will create our own comparison logic to sort them. That comparison logic will be used in the sort function in C++ STL.Algorithmcompare(str1, str2): Begin if length of str1 < length of str2, then return 1 return ... Read More
240 Views
In this article, we will learn about the web scraping technique using the Scrappy module available in Python.What is web scraping?Web scraping is used to obtain/get the data from a website with the help of a crawler/scanner. Web scrapping comes handy to extract the data from a web page that doesn't offer the functionality of an API. In python, web scraping can be done by the help of various modules namely Beautiful Soup, Scrappy & lxml.Here we will discuss web scraping using the Scrappy module.For that, we first need to install Scrappy.Type in the terminal or command prompt>>> pip install ... Read More
350 Views
In this section we will see another sorting problem. Suppose we have two arrays A1 and A2. We have to sort A1 in such a way that the relative order among the elements will be same as those are in A2. If some elements are not present in A2, then they will be appended after the sorted elements. Suppose A1 and A2 are the following −A1 = {2, 1, 2, 1, 7, 5, 9, 3, 8, 6, 8} A2 = {2, 1, 8, 3}After the sorting A1 will be like below −A1 = {2, 2, 1, 1, 8, 8, 3, ... Read More
706 Views
Deserialization is the process of converting JSON data back into Java objects. Gson provides a simple way to do this using the fromJson() method. Custom JSON de-serialization with Gson Gson is a Java library developed by Google to convert Java objects into their JSON format and vice versa. Custom JSON is a way we can modify or extend the standard JSON format so that it can suit our specific needs. To use the Gson library, we need to add the Gson library to our project. If you are using Maven, add this to your pom.xml file: com.google.code.gson gson 2.8.9 ... Read More
403 Views
Here we will see one interesting problem to sort an array based on the set-bits. When an element in the array has higher number of set-bits, then that will be placed before another element which has lower number of set bits. Suppose some numbers are 12, 15, 7. So the set bits are basically number of 1’s in their binary representation. These are 1100 (12), 1111 (15), and 0111 (7). So after sorting it will be look like this −1111, 0111, 1100 (15, 7, 12)Here we have to find the number of set-bits at first. Then we will use the ... Read More
2K+ Views
If you have ever worked with JSON in Java, you might have used classes like JSONObject, JSONArray, JsonParser, etc. These classes are part of the org.json library. We use these classes to build JSON or parse JSON. But behind the scenes, these classes use a class called JSONTokener. In this article, we will learn about the JSONTokener class and its importance in Java. What is JSONTokener? The JSONTokener class is like a tool that reads a JSON string step by step, breaking it into smaller parts called tokens. It is like a helper that makes it easier to understand and ... Read More
488 Views
Stream method of array class introduced in Java 8. Let us see an example wherein we are counting empty strings, eliminating empty strings, getting a list of square of distinct numbers, displaying random numbers, etc −Exampleimport java.util.ArrayList; import java.util.Arrays; import java.util.IntSummaryStatistics; import java.util.List; import java.util.Random; import java.util.stream.Collectors; import java.util.Map; public class Java8Tester { public static void main(String args[]) { System.out.println("Using Java 7: "); // Count empty strings List strings = Arrays.asList("abc", "", "bc", "efg", "abcd", "", "jkl"); System.out.println("List: " +strings); long count = getCountEmptyStringUsingJava7(strings); ... Read More
4K+ Views
In Java, counting the occurrences of each character in a string is a common task that can be efficiently performed using a HashMap. A HashMap allows us to store key-value pairs, where each unique character in the string is a key, and the value is the count of its occurrences. Problem Statement Given a string, we need to count how many times each character appears in the string. For example, in the string thisisit, the character t appears twice, h appears once, i appears three times, and s appears twice. Input String myStr = "thisisit"; Output Counting ... Read More
5K+ Views
What is a Palindrome? A palindrome is a number, string or any data value, which reads the same from backwards. i.e. If we reverse a value and compare it with its original value, the result should be true. For example, strings like "ABA", "RADAR", "BABAB" and numbers like 121, 12321 are palindromes. Checking for Palindrome Using Java Program One way to verify if a string, number or, an alphanumeric value is a palindrome is by reversing the given it. Following are the steps - Get the value to be verified. Reverse the contents of the given value. Compare ... Read More