Found 33676 Articles for Programming

Java program to check if none of the string in the list matches the condition

Nancy Den
Updated on 29-Sep-2024 02:47:46

847 Views

In this article, you will learn how to check if none of the strings in a list start with a specific letter using Java. This approach is useful for validating or filtering data. We will use the Stream API to evaluate the condition and return a boolean result based on whether any string starts with the given letter. Problem Statement Write a program in Java to check if none of the strings in the list matches the condition. Input pqr, stu, vwx, yza, vwxy Output No match for the starting letter as f? = true Steps to check if none of ... Read More

How to check if input is numeric in C++?

Nishu Kumari
Updated on 30-May-2025 18:07:17

6K+ Views

Numeric input means a value that contains only digits from 0 to 9, without any letters or special characters. In this article, we'll show you how to write a C++ program to check whether the input is numeric. Let's understand this with a few examples: //Example 1: Input: 12345 Output: Valid numeric input //Example 2: Input: 12a5 Output: Not a numeric input We will cover two common ways to check if the input is numeric or not in C++. Using std::getline with std::isdigit Check Using stringstream to Parse ... Read More

How to find the size of an int[] in C/C++?

Nishu Kumari
Updated on 30-May-2025 18:05:34

8K+ Views

In C and C++, arrays can store multiple values of the same data type. This problem is about finding how many elements are present in a statically declared int[] array (not pointers or dynamically allocated arrays). We'll learn how to find the size of an int[] in both C and C++. Let's understand this with an example: //Example 1 input: int numbers[] = {10, 20, 30, 40, 50}; This array has 5 elements. Output: Number of elements: 5 //Example 2: Input: int values[] = {1, 2, 3}; This array has 3 elements. Output: Number of elements: 3 ... Read More

Java Program to convert integer to String with Map

Alshifa Hasnain
Updated on 07-Jan-2025 18:55:45

706 Views

In this article, we will learn to convert integers to String with Map in Java. The Stream API has become an essential tool for processing collections of data in a more declarative and readable way. Instead of using traditional loops, streams allow developers to filter, map, and perform other operations on data with minimal code Problem Statement Given an integer, we need to convert it to its string representation where the integer is treated as a character (e.g., 5 becomes "5", 10 becomes "10"). We'll use a Map to define the integer-to-string mappings and retrieve the string equivalent for a ... Read More

How to convert File into a Stream in Java?

Nancy Den
Updated on 30-Jul-2019 22:30:26

732 Views

Let’s say we have a file “input.txt” here in the directory E:/ with the following content:Open a file with Bufferedreader. We have taken the above file here which is located at E: directory;BufferedReader buffReader = Files.newBufferedReader(Paths.get("E:\input.txt"), StandardCharsets.UTF_8);Now get the stream of lines from the above file and display:buffReader.lines().forEach(System.out::println);The following is an example to convert File into a Stream in Java:Exampleimport java.io.BufferedReader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; public class Demo {    public static void main(String[] argv) throws Exception {       BufferedReader buffReader = Files.newBufferedReader(Paths.get("E:\input.txt"), StandardCharsets.UTF_8);       System.out.println("Stream of lines...");       buffReader.lines().forEach(System.out::println);    } ... Read More

How to implement a copy constructors in C++?

Anvi Jain
Updated on 30-Jul-2019 22:30:26

523 Views

Here we will see how the copy constructors are implemented in C++. Before discussing that we should know what is the copy constructor.The copy constructor is a constructor which creates an object by initializing it with an object of the same class, which has been created previously. The copy constructor is used to −Initialize one object from another of the same type.Copy an object to pass it as an argument to a function.Copy an object to return it from a function.If a copy constructor is not defined in a class, the compiler itself defines one. If the class has pointer ... Read More

Print a number 100 times without using loop, recursion and macro expansion in C

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

558 Views

In this section we will see how to print a number 100 times in C. There are some constraints. We cannot use loops, recursions or macro expansions.To solve this problem we will use the setjump and longjump in C. The setjump() and longjump() is located at setjmp.h library. The syntax of these two functions are like below.Example#include #include jmp_buf buf; main() {    int x = 1;    setjmp(buf); //set the jump position using buf    printf("5"); // Prints a number    x++;    if (x

Program to display hostname and IP address C

Smita Kapse
Updated on 30-Jul-2019 22:30:26

550 Views

In this section we will see how to see the Host name and IP address of the local system in an easier way. We will write a C program to find the host name and IP.Some of the following functions are used. These functions have a different task. Let us see the functions and their tasks.FunctionDescriptiongethostname()It finds the standard host name for the local computer.gethostbyname()It finds the host information corresponding to a host name from host databaseiten_ntoa()It converts an IPv4 Internet network address into an ASCII string into dotted decimal format.Example#include #include #include #include #include ... Read More

How to transform List string to upper case in Java?

Daniol Thomas
Updated on 30-Jul-2019 22:30:26

4K+ Views

Let’s first create a List string:List list = Arrays.asList("David", "Tom", "Ken", "Yuvraj", "Gayle");Now transform the above list to upper case:list.stream().map(players -> players.toUpperCase())To display, use forEach():list.stream().map(players -> players.toUpperCase()) .forEach(players -> System.out.print(players + ""));The following is an example to transform List string to upper case:Exampleimport java.util.Arrays; import java.util.List; public class Demo {    public static void main(final String[] args) {       List list = Arrays.asList("David", "Tom", "Ken", "Yuvraj", "Gayle");       System.out.print("List = "+list);       System.out.print("Uppercase strings = ");       list.stream().map(players -> players.toUpperCase()) .forEach(players -> System.out.print(players + ""));    } }OutputList = [David, Tom, Ken, ... Read More

What happens when JDialog is set with Modality type MODELESS in Java

Daniol Thomas
Updated on 30-Jul-2019 22:30:26

130 Views

Modeless dialog boxes are on the screen and are available for use. The following is an example to set JDialog with Modality type MODELESS:Exampleimport java.awt.Cursor; import java.awt.Dialog.ModalityType; import java.awt.Dimension; import java.awt.event.ActionEvent; import javax.swing.AbstractAction; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JFrame; public class SwingDemo {    public static void main(String[] args) {       JFrame frame = new JFrame();       frame.setSize(new Dimension(600, 400));       JDialog dialog = new JDialog(frame, "New", ModalityType.MODELESS);       dialog.setSize(300, 300);       frame.add(new JButton(new AbstractAction("Click to generate") {          @Override          public void actionPerformed(ActionEvent ... Read More

Advertisements