
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

9K+ Views
With Java Swing, you can set JLabel size as preferred size different than the default −JLabel label.setPreferredSize(new Dimension(250, 100));The following is an example to change JLabel size −Exampleimport java.awt.Color; import java.awt.Dimension; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); JLabel label; label = new JLabel("This is demo label!", JLabel.RIGHT); label.setVerticalAlignment(JLabel.TOP); label.setFont(new Font("Verdana", Font.PLAIN, 15)); label.setPreferredSize(new Dimension(250, 100)); label.setForeground(new Color(120, 90, 40)); label.setBackground(new ... Read More

7K+ Views
The toString() method of the java.sql.Timestamp class returns the JDBC escape format of the time stamp of the current Timestamp object as String variable.i.e. using this method you can convert a Timestamp object to a String.//Retrieving the Time object Timestamp timestampObj = rs.getTimestamp("DispatchTimeStamp"); //Converting the Time object to String format String time_stamp = timestampObj.toString();ExampleLet us create a table with the name dispatches_data in MySQL database using CREATE statement as shown below:CREATE TABLE dispatches_data( ProductName VARCHAR(255), CustomerName VARCHAR(255), DispatchTimeStamp timestamp, Price INT, Location VARCHAR(255));Now, we will insert 5 records in dispatches_data table using INSERT statements:insert into ... Read More

834 Views
Let’s say the following is our String List −List list = Arrays.asList("Football", "Basketball", "Hockey", "Cricket", "Fencing");Now, map to add string to each element −List str = list.stream().map(name -> "Sports " + name + " Outdoor") .collect(Collectors.toList());Above, we have added “Sports” and “Outdoor” strings to each element.The following is an example to Map and add string value to each element in Java −Exampleimport java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class Demo { public static void main(String[] args) { List list = Arrays.asList("Football", "Basketball", "Hockey", "Cricket", "Fencing"); List str = list.stream().map(name -> "Sports " ... Read More

708 Views
In this article, we will learn to map a String list to lowercase and sort in Java. We need to manipulate the elements of a list, such as converting all strings to lowercase and sorting them. This is particularly useful when dealing with user input, file processing, or data normalization. Problem Statement Given a list of strings, we want to convert all strings to lowercase and sort the list in reverse alphabetical order.For Example: Input ["Apple", "banana", "Cherry", "date"] Output ["date", "cherry", "banana", "apple"] Using Streams API The Streams API provides a useful and functional approach to processing ... Read More

475 Views
At first, we have set the stream −Stream.of(3.5, 4.7, 7.9, 8.2, 9.1, 10.5, 12.3, 15.8)Now to Map double to int Object, use mapToObj −.mapToInt(Double::intValue) .mapToObj(a -> "val" + a)The following is an example to Map double to int Object with mapToInt and mapToObj −Exampleimport java.util.stream.Stream; public class Demo { public static void main(String[] args) throws Exception { Stream.of(3.5, 4.7, 7.9, 8.2, 9.1, 10.5, 12.3, 15.8) .mapToInt(Double::intValue) .mapToObj(a -> "val" + a) .forEach(System.out::println); } }Outputval3 val4 val7 val8 val9 val10 val12 val15

203 Views
To Map IntStream to String object, use mapToObj and within that set the values −.mapToObj(val -> "z" + val)Before that, we used range() on IntStream −IntStream.range(1, 10)The following is an example to map IntStream to String object in Java −Exampleimport java.util.stream.IntStream; public class Demo { public static void main(String[] args) throws Exception { IntStream.range(1, 10) .mapToObj(val -> "z" + val) .forEach(System.out::println); } }Outputz1 z2 z3 z4 z5 z6 z7 z8 z9

3K+ Views
Let’s say the following is our String List −List list = Arrays.asList("Jonny", "David", "Tony", "Jacob", "Smith", "Bravo", "Gayle", "John");Now filter the string value with starting letter −Stream stream = list.stream().filter(name -> name.startsWith("J"));The following is an example to filter string value with starting letter −Exampleimport java.util.Arrays; import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; public class Demo { public static void main(String[] args) { List list = Arrays.asList("Jonny", "David", "Tony", "Jacob", "Smith", "Bravo", "Gayle", "John"); System.out.println("List with elements..."); for (String res : list) { System.out.print(res+" ... Read More

3K+ Views
Let’s say the following is String array, which we have converted to List −Arrays.asList("DE", "GH", "JK", "MN", "PQ", "RS", "TU", "VW", "XY", "BC")Now filter String stream and map to lower case −.stream() .filter(a-> a.startsWith("V")) .map(String::toLowerCase)To sort now, use the sorted() and display using forEach().The following is an example to filter string stream and map to lowercase −Exampleimport java.util.Arrays; public class Demo { public static void main(String[] args) throws Exception { Arrays.asList("DE", "GH", "JK", "MN", "PQ", "RS", "TU", "VW", "XY", "BC") .stream() .filter(a-> a.startsWith("V")) .map(String::toLowerCase) ... Read More

2K+ Views
Let’s first create a String list −List list = new ArrayList(); list.add("wxy"); list.add("zabc"); list.add("ddd2"); list.add("def"); list.add("ghi"); list.add("wer"); list.add("uij"); list.add("wqy");To filter String list by starting value, use filter() and startsWith() −list.stream().filter((b) -> b.startsWith("w"))The following is an example to filter string list by starting value −Exampleimport java.util.ArrayList; import java.util.List; public class Demo { public static void main(final String[] args) { List list = new ArrayList(); list.add("wxy"); list.add("zabc"); list.add("ddd2"); list.add("def"); list.add("ghi"); list.add("wer"); list.add("uij"); list.add("wqy"); ... Read More

1K+ Views
Tooltip is visible whenever you will place the mouse cursor on the label. Use the setToolTipText() method to add tooltip to JLabel −label.setToolTipText("This is a demo tooltip");The following is an example to add tooltip to JLabel −Exampleimport java.awt.Color; import java.awt.Font; import javax.swing.*; import javax.swing.border.Border; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Demo"); JLabel label; label = new JLabel("Demo Label!"); label.setFont(new Font("Verdana", Font.PLAIN, 14)); label.setToolTipText("This is a demo tooltip"); Border border = BorderFactory.createLineBorder(Color.ORANGE); ... Read More