Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Access items from the ArrayList using get() function

import java.util.ArrayList;

class Main {
  public static void main(String[] args) {
    ArrayList<String> animals = new ArrayList<>();

    // add elements in the arraylist
    animals.add("Peacock");
    animals.add("Markhor");
    animals.add("Cow");
    System.out.println("ArrayList: " + animals);

    // get the element from the arraylist
    String str = animals.get(1);
    System.out.print("Element at index 1: " + str);
  }
}
Comment

Java Access ArrayList Elements

import java.util.ArrayList;

class Main {
  public static void main(String[] args) {
    ArrayList<String> animals = new ArrayList<>();

    // add elements in the arraylist
    animals.add("Cat");
    animals.add("Dog");
    animals.add("Cow");
    System.out.println("ArrayList: " + animals);

    // get the element from the arraylist
    String str = animals.get(1);
    System.out.print("Element at index 1: " + str);
  }
}
Comment

PREVIOUS NEXT
Code Example
Java :: java.lang.ArrayIndexOutOfBoundsException 
Java :: make textview invisible android 
Java :: Could not determine java version from 
Java :: Java How to use SortedSet? 
Java :: hollow pyramid star pattern in java 
Java :: render problem in android studio 
Java :: java new char array 
Java :: android canvas line thickness 
Java :: java class jar determine 
Java :: convert a int to string in java 
Java :: how to add a list in a list java 
Java :: arrays.copy 2d array 
Java :: distance point to line java 
Java :: use regex in if statement java 
Java :: greater than sign in java 
Java :: check first character of string is number java 
Java :: how to get internet speed in android programmatically 
Java :: java substring based on delimiter 
Java :: string methods in java 
Java :: how to add spaces before string in java 
Java :: java arraylist remove 
Java :: lambda java 
Java :: Create class from string variable JAVA 
Java :: get input in java 
Java :: retrofit 
Java :: convert calendar to date java 
Java :: Caused by: java.io.EOFException: SSL peer shut down incorrectly 
Java :: Java Exception handling using Java throw 
Java :: how to use string variables with an if statement in java 
Java :: how to draw a triangle in java 
ADD CONTENT
Topic
Content
Source link
Name
5+3 =