Programming Articles

Page 1584 of 2547

How to print data of specific element from an array in java?

Monica Mona
Monica Mona
Updated on 11-Mar-2026 15K+ Views

An array is a data structure/container/object that stores a fixed-size sequential collection of elements of the same type. The size/length of the array is determined at the time of creation. The position of the elements in the array is called as index or subscript. The first element of the array is stored at the index 0 and, the second element is at the index 1 and so on. Each element in an array is accessed using an expression which contains the name of the array followed by the index of the required element in square brackets. You can access an ...

Read More

How to create an array of linked lists in java?

Abhinanda Shri
Abhinanda Shri
Updated on 11-Mar-2026 5K+ Views

A linked list is a sequence of data structures, which are connected together via links.To create an array of linked lists, create required linked lists and, create an array of objects with them.Exampleimport java.util.LinkedList; public class ArrayOfLinkedList {    public static void main(String args[]) {       LinkedList list1 = new LinkedList();       list1.add("JavaFX");       list1.add("Hbase");             LinkedList list2 = new LinkedList();       list2.add("OpenCV");       list2.add("Mahout");             LinkedList list3 = new LinkedList();       list3.add("WebGL");       list3.add("CoffeeScript");       Object[] obj = {list1, list2, list3};             for (int i=0; i

Read More

How to reverse the elements of an array using stack in java?

Ramu Prasad
Ramu Prasad
Updated on 11-Mar-2026 4K+ Views

Stack is an Abstract Data Type (ADT), commonly used in most programming languages. It is named stack as it behaves like a real-world stack, for example – a deck of cards or a pile of plates, etc.A stack is first in first out, it has two main operations push and pop. Push inserts data in to it and pop retrieves data from it.To reverse an array using stack initially push all elements in to the stack using the push() method then, retrieve them back using the pop() method into another array.Exampleimport java.util.Arrays; import java.util.Stack; public class ReversinArrayUsingStack {   ...

Read More

If a number is read as a String, how to Count the no of times the highest number repeated in the string?n a. Ex: 2 4 3 4 2 4 0 -> (3)

Govinda Sai
Govinda Sai
Updated on 11-Mar-2026 186 Views

To do so, Trim the given string and split it using the split() method (Removing the empty spaces in-between).Create an integer array and in loop convert each element of the string array to an integer using Integer.parseInt() method and assign it to the respective element of the integer array.Sort the obtained integer array, since this method sorts the elements of the array in ascending order the last element will be the maximum of the array. Create an integer variable count with initial value 0. Compare each element of the array with the maximum value, each time a match occurs increment the count. The final value ...

Read More

How to store the contents of arrays in a file using Java?

Ramu Prasad
Ramu Prasad
Updated on 11-Mar-2026 3K+ Views

You can use write data into a file using the Writer classes. In the example given below, we are writing the contents of the array using the BufferedWriter.Exampleimport java.io.BufferedWriter; import java.io.FileWriter; public class WritingStringArrayToFile {    public static void main(String args[]) throws Exception {       String[] myArray = {"JavaFX", "HBase", "OpenCV", "Java", "Hadoop", "Neo4j"};       BufferedWriter writer = new BufferedWriter(new FileWriter("myFile.txt", false));       for(int i = 0; i < myArray.length; i++) {          writer.write(myArray[i].toString());          writer.newLine();       }       writer.flush();       ...

Read More

How to convert Java Array to Iterable?

V Jyothi
V Jyothi
Updated on 11-Mar-2026 9K+ Views

To make an array iterable either you need to convert it to a stream or as a list using the asList() or stream() methods respectively. Then you can get an iterator for these objects using the iterator() method.Exampleimport java.util.Arrays; import java.util.Iterator; public class ArrayToIterable {    public static void main(String args[]){       Integer[] myArray = {897, 56, 78, 90, 12, 123, 75};       Iterator iterator = Arrays.stream(myArray).iterator();       while(iterator.hasNext()) {          System.out.println(iterator.next());       }    } }Output897 56 78 90 12 123 75As mentioned above, you can also convert an ...

Read More

How do I write interface names in Java?

mkotla
mkotla
Updated on 11-Mar-2026 751 Views

While writing an interface/class names you need to keep the following points in mind. First letter of the interface/class name should be capital and remaining letters should be small (mixed case). interface Sample Likewise, first letter of each word in the name should be capital an remaining letters should be small. interface MYInterface Keeping interface names simple and descriptive is suggestable. Better not to use acronyms while writing interface/class names. Example interface MyInterface { void sample(); void demo(); } public class Test ...

Read More

How do I write constants names in Java?

vanithasree
vanithasree
Updated on 11-Mar-2026 793 Views

While writing the name of the constants it is suggested to write all the letters in upper case. If constant contains more than one word they should be separated by underscore (_). Example public class ConstantsTest { public static final int MIN_VALUE = 22; public static final int MAX_VALUE = 222; public static void main(String args[]) { System.out.println("Value of the constant MIN_VALUE: "+MIN_VALUE); System.out.println("Value of the constant MAX_VALUE: "+MAX_VALUE); } } Output Value of the constant MIN_VALUE: 22 Value of the constant MAX_VALUE: 222

Read More

How to find the intersection of two arrays in java?

V Jyothi
V Jyothi
Updated on 11-Mar-2026 8K+ Views

To find the intersection of two arrays in java use two loops. The outer loop is to iterate the elements of the first array whereas, the second loop is to iterate the elements of the second array. Within the second loop compare the elements of the two arrays:Examplepublic class IntersectionOfTwoArrays {    public static void main(String args[]) {       int myArray1[] = {23, 36, 96, 78, 55};       int myArray2[] = {78, 45, 19, 73, 55};       System.out.println("Intersection of the two arrays ::");             for(int i = 0; i

Read More

What is the difference between method overloading and method hiding in Java?

varun
varun
Updated on 11-Mar-2026 1K+ Views

method hiding − When super class and the sub class contains same methods including parameters, and if they are static and, when called, the super class method is hidden by the method of the sub class this is known as method hiding. Example class Demo{ public static void demoMethod() { System.out.println("method of super class"); } } public class Sample extends Demo{ public static void demoMethod() { System.out.println("method of sub class"); } public ...

Read More
Showing 15831–15840 of 25,466 articles
Advertisements