Programming Articles

Page 1524 of 2547

DoubleStream.Builder build() method in Java

George John
George John
Updated on 11-Mar-2026 197 Views

The build() method of the DoubleStream.Builder class builds the stream. It transitions this builder to the built state.The syntax is as followsDoubleStream build()To use the DoubleStream.Builder class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream.Builder build() method in Java:Exampleimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream.Builder builder = DoubleStream.builder();       builder.add(34.5);       builder.add(87.1);       builder.add(35.6);       builder.add(66.1);       builder.add(36.8);       builder.add(77.4);       builder.add(88.2);       builder.add(68.9);       builder.build().forEach(System.out::println);    } }Output34.5 87.1 35.6 66.1 36.8 77.4 88.2 68.9

Read More

Java program to print a given matrix in Spiral Form.

Venkata Sai
Venkata Sai
Updated on 11-Mar-2026 4K+ Views

Following is a Java program to print the spiral form of a given matrix.Examplepublic class PrintMatrixInSpiralForm {    public static void main(String args[]){       int a[][]={{1,2,3},{4,5,6},{7,8,9}};       int w = 0;       int x = a.length-1;       int y = 0;       int z = a[0].length-1;       while(w

Read More

Check if a particular element exists in Java LinkedHashSet

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 333 Views

Use the contains() method to check if a specific element exists in LinkedHashSet or not.Let us first create a LinkedHashSet and add some elements −LinkedHashSet l = new LinkedHashSet(); l.add(new String("1")); l.add(new String("2")); l.add(new String("3")); l.add(new String("4")); l.add(new String("5")); l.add(new String("6")); l.add(new String("7"));Now, check whether it contains element “5” or not −l.contains("5")The following is an example to check if a particular element exists in LinkedHashSet −Exampleimport java.util.*; public class Demo {    public static void main(String[] args) {       LinkedHashSet l = new LinkedHashSet();       l.add(new String("1"));       l.add(new String("2"));       l.add(new ...

Read More

Program to print a matrix in Diagonal Pattern.

Venkata Sai
Venkata Sai
Updated on 11-Mar-2026 1K+ Views

Following is the Java program to print diagonal pattern of a given matrix.Examplepublic class DiagonalMatrix {    public static void main(String args[]){       int a[][]={{1,2,3},{4,5,6},{7,8,9}};       int rows = a.length;       int columns = a[0].length;       for (int i = 0; i < rows; i++) {          for (int r = i, c = 0; r >= 0 && c < columns; r--, c++){             System.out.print(a[r][c] + " ");          }          System.out.println();       }       for (int i = 1; i < columns; i++) {          for (int r = rows-1, c = i; r >= 0 && c < columns; r--, c++) {             System.out.print(a[r][c] + " ");          }          System.out.println();       }    } }Output1 4 2 7 5 3 8 6 9

Read More

Convert elements in a HashSet to an array in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 443 Views

First, create a HashSet and elements to it −HashSet hs = new HashSet(); // add elements to the hash set hs.add("B"); hs.add("A"); hs.add("D"); hs.add("E"); hs.add("C"); hs.add("F"); hs.add("K");Let us now convert the above HashSet to an array −Object[] ob = hs.toArray();The following is an example to convert elements in a HashSet to an array −Exampleimport java.util.*; public class Demo { public static void main(String args[]) { // create a hash set HashSet hs = new HashSet(); // add elements to ...

Read More

ArrayBlockingQueue remainingCapacity() Method in Java

Ankith Reddy
Ankith Reddy
Updated on 11-Mar-2026 137 Views

The remainingCapacity() method of the ArrayBlockingQueue class in Java is used to return the number of additional elements that the queue can adopt without blocking.The syntax is as followsint remainingCapacity()To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to implement remainingCapacity() method of Java ArrayBlockingQueue classExampleimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(10);       q.add(120);       q.add(400);       q.add(450);       q.add(500);       System.out.println("ArrayBlockingQueue = " + q); ...

Read More

Program for converting Alternate characters of a string to Upper Case.

Venkata Sai
Venkata Sai
Updated on 11-Mar-2026 6K+ Views

You can convert a character to upper case using the toUpperCase() method of the character class.ExampleFollowing program converts alternate characters of a string to Upper Case.import java.util.Scanner; public class UpperCase {    public static void main(String[] args) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter a string :");       String str = sc.nextLine();       str = str.toLowerCase();       char[] ch = str.toCharArray();       for(int i=0; i

Read More

C++ Program to Apply Above-Below-on Test to Find the Position of a Point with respect to a Line

Anvi Jain
Anvi Jain
Updated on 11-Mar-2026 646 Views

This is a C++ program to apply Above-Below-on Test to find the position of a point with respect to a Line. For any point t (xt, yt) on the plane, its position with respect to the line L connecting m and n is found by calculating the scalar s −Y = A xt + B yt + CIf Y< 0, t lies in the clockwise halfplane of L; if Y>0, t lies on the counter-clockwise halfplane; if Y= 0, t lies on L.AlgorithmBegin    Take the points as input.    For generating equation of the line, generate random numbers for ...

Read More

Convert a Set into a List in Java

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 332 Views

First, create a Set and add elements −Set s = new HashSet(); s.add("P"); s.add(new Date()); s.add(new Long(898999)); s.add("Q"); s.add("R"); s.add(new Integer(1));Convert the above Set to a List −List l = new ArrayList(s);The following is an example to convert a set into a list in Java −Exampleimport java.util.ArrayList; import java.util.Date; import java.util.List; import java.util.Set; import java.util.HashSet; public class Demo {    public static void main(String[] args) {       Set s = new HashSet();       s.add("P");;       s.add(new Date());       s.add(new Long(898999));       s.add("Q");       s.add("R");       s.add(new ...

Read More

The hashCode() method of CopyOnWriteArrayList method in Java

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 262 Views

To get the hash code value of the list, you need to use the hashCode() method of the CopyOnWriteArrayList class.The syntax is as followspublic int hashCode()To work with CopyOnWriteArrayList class, you need to import the following packageimport java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class hashCode() method in JavaExampleimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList();       arrList.add(30);       arrList.add(40);       arrList.add(60);       arrList.add(70);       arrList.add(90);       arrList.add(100);       arrList.add(120);     ...

Read More
Showing 15231–15240 of 25,466 articles
Advertisements