Found 34483 Articles for Programming

What does the method ensureCapacity(int, minCapacity) do in java?

Govinda Sai
Updated on 25-Feb-2020 10:10:30

116 Views

The ensureCapacity(int minCapacity) method of the class java.util.ArrayList increases the capacity of this ArrayList instance, if necessary, to ensure that it can hold at least the number of elements specified by the minimum capacity argument.Exampleimport java.util.ArrayList; public class ArrayListDemo {    public static void main(String args[]) {       ArrayList arrlist = new ArrayList(5);       arrlist.add(10);       arrlist.add(50);       arrlist.add(30);       arrlist.ensureCapacity(15);       for (Integer number : arrlist) {          System.out.println("Number = " + number);       }    } }OutputNumber = 10 Number = 50 Number = 30

What does the method lastIndexOf(obj o) do in java?

Ramu Prasad
Updated on 20-Feb-2020 12:20:20

60 Views

The lastIndexOf(Object) method of the class java.util.ArrayList returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element.Exampleimport java.util.ArrayList; public class ArrayListDemo {    public static void main(String[] args) {       ArrayList arrlist = new ArrayList(5);       arrlist.add("G");       arrlist.add("E");       arrlist.add("F");       arrlist.add("M");       arrlist.add("E");       System.out.println("Size of list: " + arrlist.size());       for (String value : arrlist) {          System.out.println("Value = " + value);     ... Read More

What is the difference between the size of ArrayList and length of Array in Java?

Srinivas Gorla
Updated on 30-Jul-2019 22:30:21

2K+ Views

ArrayList doesn't have length() method, the size() method of ArrayList provides the number of objects available in the collection.Array has length property which provides the length or capacity of the Array. It is the total space allocated during the initialization of the array.

How to concatenate lists in java?

Abhinanda Shri
Updated on 30-Jul-2019 22:30:21

466 Views

The addAll(Collection

What does the method indexOf(obj o) do in java?

Sravani S
Updated on 20-Feb-2020 12:19:30

100 Views

The indexOf(Object) method of the java.util.ArrayList class returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element.Exampleimport java.util.ArrayList; public class ArrayListDemo {    public static void main(String[] args) {       ArrayList arrlist = new ArrayList(5);       arrlist.add("G");       arrlist.add("E");       arrlist.add("F");       arrlist.add("M");       System.out.println("Size of list: " + arrlist.size());       for (String value : arrlist) {          System.out.println("Value = " + value);       }     ... Read More

What does the method search(Object o) do in java?

Paul Richard
Updated on 25-Feb-2020 09:59:50

290 Views

The search(Object o) method is used to return the 1-based position where an object is on this stack.Exampleimport java.util.*; public class StackDemo {    public static void main(String args[])  {             Stack st = new Stack();       st.push("Java");       st.push("Source");       st.push("code");       System.out.println("Searching 'code' in stack: "+st.search("code"));    } }OutputSearching 'code' in stack: 

What does the method get(int) do in java?

V Jyothi
Updated on 20-Feb-2020 12:18:14

393 Views

The get(int index) method of the java.util.ArrayList class returns the element at the specified position in this list.Exampleimport java.util.ArrayList; public class ArrayListDemo {    public static void main(String[] args) {       ArrayList arrlist = new ArrayList(5);       arrlist.add(15);       arrlist.add(22);       arrlist.add(30);       arrlist.add(40);       for (Integer number : arrlist) {          System.out.println("Number = " + number);       }       int retval=arrlist.get(3);       System.out.println("Retrieved element is = " + retval);    } }OutputNumber = 15 Number = 22 Number = 30 Number = 40 Retrieved element is = 40

What does the method empty() do in java?

Vikyath Ram
Updated on 25-Feb-2020 10:00:29

100 Views

The empty() method is used to test if this stack is or not.Exampleimport java.util.*; public class StackDemo {    public static void main(String args[]) {           Stack st = new Stack();       st.push("Java");       st.push("Source");       st.push("code");       System.out.println("Is stack empty: "+st.empty());    } }OutputIs stack empty: false

What does the method peek() do in java?

Rishi Raj
Updated on 25-Feb-2020 10:01:14

207 Views

The peek() method is used to look at the object at the top of this stack without removing it from the stack.Exampleimport java.util.*; public class StackDemo {    public static void main(String args[]) {             Stack st = new Stack();       st.push("Java");       st.push("Source");       st.push("code");       System.out.println("Top object is: "+st.peek());    } }OutputTop object is: code

What is the difference between Java and Core Java?

radhakrishna
Updated on 30-Jul-2019 22:30:21

778 Views

Java is a programming language, whereas Core Java is a computing platform. Java Platform Standard Edition is Core Java, which is also called Java SE. The following are the computing following supported by Java, which also has Core Java as its part:Java SE Java Standard Edition used to develop desktop applications. A well-known implementation of Java SE is the Java Development Kit (JDK).Java EE Java Enterprise Edition i.e. Java 2 Platform, Enterprise Edition or J2EE. Java EE is used for applications running on servers. Java ME Java Micro Edition is used for applications running on mobile phones.Java SE is the Standard Edition and also ... Read More

Advertisements