
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 9150 Articles for Object Oriented Programming

833 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

705 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

473 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

201 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

677 Views
Use the createLineBorder() method to ad line border to JLabel −Border border = BorderFactory.createLineBorder(Color.ORANGE); label.setBorder(border);Above, we have set the line border to color orange.The following is an example to add line border to JLabel −Examplepackage my; import 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!", JLabel.RIGHT); label.setFont(new Font("Verdana", Font.PLAIN, 13)); Border border = BorderFactory.createLineBorder(Color.ORANGE); label.setBorder(border); frame.add(label); ... Read More

8K+ Views
JLabel Left AlignedThe following is an example to set left alignment for JLabel −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo { public static void main(String args[]) { JFrame frame = new JFrame("Label Demo"); JLabel label; label = new JLabel("Left aligned!", JLabel.LEFT); label.setFont(new Font("Verdana", Font.PLAIN, 13)); frame.add(label); frame.setSize(500, 300); frame.setVisible(true); } }OutputJLabel Center AlignedThe following is an example to set center alignment for JLabel −Exampleimport java.awt.Font; import javax.swing.*; public class SwingDemo { public static void main(String args[]) ... Read More