
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
Found 33676 Articles for Programming

2K+ Views
The following is an example to add items on runtime on a JComboBox in Java:Exampleimport java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JFrame; public class SwingDemo { public static void main(String[] args) throws Exception { JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JComboBox combo = new JComboBox(new String[] { "One", "Two", "Three", "Four", "Five", "Six" }); JButton add = new JButton("Add"); add.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { ... Read More

5K+ Views
First, create a List with String elements:List myList = new ArrayList(); myList.add("pqr"); myList.add("stu"); myList.add("vwx"); myList.add("yza"); myList.add("bcd"); myList.add("efg"); myList.add("vwxy");Use the startsWith() method to check if any of the above string in the myList begins with a specific letter:myList.stream().anyMatch((a) -> a.startsWith("v"));TRUE is returned if any of the string begins with the specific letter, else FALSE.The following is an example to check if any String in the list starts with a letter:Exampleimport java.util.ArrayList; import java.util.List; public class Demo { public static void main(final String[] args) { List myList = new ArrayList(); myList.add("pqr"); myList.add("stu"); ... Read More

756 Views
In this article, we will learn to get the reverse of an Integer array with Lambda expressions in Java. By utilizing the Arrays.sort() method along with a custom comparator defined as a lambda expression, we can efficiently reorder the elements of the array in descending order. Lambda expressions are a concise way to represent functional interfaces, allowing you to write cleaner and more readable code. Problem Statement Write a program in Java to get the reverse of an Integer array with Lambda expressions − Input arr = {20, 50, 75, 100, 120, 150, 170, 200} Output Integer Array elements... 20 50 ... Read More

318 Views
At first, let us create and array of strings:String[] strArr = { "ABCD", "AB", "ABCDEFG", "ABC", "A", "ABCDE", "ABCDEF", "ABCDEFGHIJ" }Now, for longest to shortest pattern, for example ABCDEFGHIJ, ABCDEFG, ABCDEF, etc.; get the length of both the string arrays and work them like this:Arrays.sort(strArr, (str1, str2) → str2.length() - str1.length());The following is an example to sort array of strings by their lengths with longest to shortest pattern in Java:Exampleimport java.util.Arrays; public class Demo { public static void main(String[] args) { String[] strArr = { "ABCD", "AB", "ABCDEFG", "ABC", "A", "ABCDE", "ABCDEF", "ABCDEFGHIJ" }; ... Read More

770 Views
In this article, we will learn how to display a webpage in JEditorPane using Java. The program will load a specified webpage, and display it within a GUI window. If the connection to the webpage fails, a message will appear indicating the connection issue. This setup can be useful for embedding simple web content within Java applications. Steps to display a webpage in JEditorPaneFollowing are the steps to display a webpage in JEditorPane −We will import the necessary classes from the java.io package and javax.swing package.Create a JEditorPane object to serve as the component that will display the webpage.Use the setPage() ... Read More

130 Views
Let’s say we have the following string:String str = "YuBM787Nm";Now to display it as IntStream, use filter() and map() as shown below:int res = str.chars() .filter(Character::isDigit) .map(ch → Character.valueOf((char) ch)).sum();The following is an example to display string as IntStream:Examplepublic class Demo { public static void main(String[] args) { String str = "YuBM787Nm"; int res = str.chars() .filter(Character::isDigit) .map(ch -> Character.valueOf((char) ch)).sum(); System.out.println("String as IntStream = "+res); } }OutputString as IntStream = 166

907 Views
Use HTMLEditorKitt to change the font size with HTML. With that, use the JEditorPane setText() method to set HTML:HTMLEditorKit kit = new HTMLEditorKit(); editorPane.setEditorKit(kit); editorPane.setSize(size); editorPane.setOpaque(true); editorPane.setText(" This is a demo text with a different font!");The following is an example to change font size with HTML in Java Swing JEditorPane:Exampleimport java.awt.BorderLayout; import java.awt.Container; import java.awt.Dimension; import javax.swing.JEditorPane; import javax.swing.JFrame; import javax.swing.text.html.HTMLEditorKit; public class SwingDemo extends JFrame { public static void main(String[] args) { SwingDemo s = new SwingDemo(); s.setSize(600, 300); Container container = s.getContentPane(); s.demo(container, container.getSize()); ... Read More

287 Views
Let us first create a List:List emp = Arrays.asList( new Employee("John", "Marketing", 5), new Employee("David", "Operations", 10));We have class Employee with name, department and rank of employees.Now, create summary for the rank like count, average, sum, etc:IntSummaryStatistics summary = emp .stream() .collect(Collectors.summarizingInt(p -> p.rank));The following is an example to create IntSummaryStatistics from Collectors in Java:Exampleimport java.util.Arrays; import java.util.IntSummaryStatistics; import java.util.List; import java.util.stream.Collectors; public class Demo { public static void main(String[] args) throws Exception { List emp = Arrays.asList(new Employee("John", "Marketing", 5), new Employee("David", "Operations", 10)); IntSummaryStatistics summary = emp .stream() .collect(Collectors.summarizingInt(p → ... Read More

3K+ Views
In general, Java Array is a collection of homogeneous elements and Streams are sequence of objects from a source, which supports aggregate operations. We can create a IntStream object holding a sequence of integer values. To convert the integer array to an IntStream object you need to use the Arrays.stream() method. IntStream: The IntStream extends the BaseStream interface. It defines the stream of primitive integer value. We can import the IntStream class from java.util package. The Arrays.stream() method The Arrays.stream() method creates a sequential stream from an array. It is a static method in the Arrays. Following is the syntax ... Read More

295 Views
The C library function int remove(const char *filename) deletes the given filename so that it is no longer accessible.Following is the declaration for remove() function.int remove(const char *filename)This function takes the filename. This is the C string containing the name of the file to be deleted. On success, zero is returned. On error, -1 is returned, and errno is set appropriately.Example#include #include int main () { int ret; FILE *fp; char filename[] = "file.txt"; fp = fopen(filename, "w"); fprintf(fp, "%s", "This is tutorialspoint.com"); fclose(fp); ret = remove(filename); if(ret == 0) { ... Read More