Java Articles

Page 116 of 450

How to convert an array to string in java?

Nikitha N
Nikitha N
Updated on 11-Mar-2026 881 Views

The Arrays class of the java.util package provides toString() methods for all primitive data types and object. These methods accept an array and return its string representation.Therefore, to convert an array to string pass the required array to this method.Exampleimport java.util.Arrays; public class ArrayToString {    public static void main(String args[]) throws Exception {       int[] myArray = {23, 93, 56, 92, 39};       String str = Arrays.toString(myArray);       System.out.println(str);    } }Output[23, 93, 56, 92, 39]

Read More

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

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

What is the difference between compile time polymorphism and runtime polymorphism in java?

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

If we perform (achieve) method overriding and method overloading using instance methods, it is run time (dynamic) polymorphism. In dynamic polymorphism the binding between the method call an the method body happens at the time of execution and, this binding is known as dynamic binding or late binding. Example class SuperClass{ public static void sample(){ System.out.println("Method of the super class"); } } public class RuntimePolymorphism extends SuperClass { public static void sample(){ System.out.println("Method of the sub class"); ...

Read More

What is Is-a relationship in Java?

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

IS-A is a way of saying: This object is a type of that object. Let us see how the extends keyword is used to achieve inheritance.Examplepublic class Animal { } public class Mammal extends Animal { } public class Reptile extends Animal { } public class Dog extends Mammal { }Now, based on the above example, in Object-Oriented terms, the following are true −Animal is the superclass of Mammal class.Animal is the superclass of Reptile class.Mammal and Reptile are subclasses of Animal class.Dog is the subclass of both Mammal and Animal classes.Exampleclass Animal { } class Mammal extends Animal { ...

Read More
Showing 1151–1160 of 4,498 articles
« Prev 1 114 115 116 117 118 450 Next »
Advertisements