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 2667 of 3366
744 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
538 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
568 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
564 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
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
138 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
237 Views
Declare and initialize an Integer array:Integer[] arr = {50, 100, 150, 200, 300, 400, 500, 600, 700, 800, 1000};Now, create a stream with the above elements:Stream stream = Arrays.stream(arr);To convert the above stream to list, use Collectors.toList():stream.collect(Collectors.toList()The following is an example to convert Stream to List:Exampleimport java.util.Arrays; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { Integer[] arr = {50, 100, 150, 200, 300, 400, 500, 600, 700, 800, 1000}; Stream stream = Arrays.stream(arr); System.out.println("Stream = "+stream.collect(Collectors.toList())); } }OutputStream = [50, 100, 150, 200, 300, 400, 500, 600, 700, 800, 1000]
167 Views
Let us first create a List:List list = Arrays.asList(25, 50, 100, 200, 250, 300, 400, 500);Now, create a stream from the List:Stream stream = list.stream(); Arrays.toString(stream.toArray()));The following is an example to retrieve a Stream from a ListExampleimport java.util.Arrays; import java.util.List; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { List list = Arrays.asList(25, 50, 100, 200, 250, 300, 400, 500); System.out.println("List elements..."); for (int res : list) { System.out.println(res); } Stream stream = list.stream(); System.out.println("Stream = "+Arrays.toString(stream.toArray())); } }OutputList elements... 25 50 100 200 250 300 400 500 Stream = [25, 50, 100, 200, 250, 300, 400, 500]
8K+ Views
Here we will see how to get the modulus of two floating or double type data in C. The modulus is basically finding the remainder. For this, we can use the remainder() function in C. The remainder() function is used to compute the floating point remainder of numerator/denominator.So the remainder(x, y) will be like below.remainder(x, y) = x – rquote * yThe rquote is the value of x/y. This is rounded towards the nearest integral value. This function takes two arguments of type double, float, long double, and returns the remainder of the same type, that was given as argument. ... Read More
2K+ Views
Here we will see three functions. These functions are trunc(), truncf() and the truncl(). These functions are used to convert floating point values into truncated form.The trunc() FunctionThis function is used to truncate double type value. And return only the integer part. The syntax is like below.double trunc(double argument)Example#include #include main() { double a, b, x, y; x = 53.26; y = 75.86; a = trunc(x); b = trunc(y); printf("The value of a: %lf", a); printf("The value of a: %lf", b); }OutputThe value of a: 53.000000 The value of a: 75.000000The ... Read More