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 :: eliminar el primer caracter de un string java 
Java :: converting string to int in java 
Java :: Java Create an InputStream 
Java :: prime numbers program in java 
Java :: main method in java 
Java :: java polymorphism 
Java :: remove all element in a list java 
Java :: open new fragment from fragment 
Java :: deserialize list jackson 
Java :: setter getter array java 
Java :: how to change toolbar name in android studio 
Java :: Example of Creating a Java Stack 
Java :: how to convert iso-8859-1 to utf-8 in java 
Java :: android foreground services set auto cancel not working 
Java :: constructor in java 
Java :: fragment view in XML android 
Java :: how to change resource color to int color in android 
Java :: java spring set private field in test 
Java :: stream.concat 
Java :: add infinite numbers to variable java 
Java :: scanf in java 
Java :: generate random number using math.random in java 
Java :: date to yyMMdd conversion 
Java :: module java.base does not "opens java.io" to unnamed module 
Java :: How to output error in java 
Java :: how to recognize a pressed key in java 
Java :: split in java 
Java :: Bukkit plugin player variable 
Java :: what is object in java 
Java :: how to make window in java 
ADD CONTENT
Topic
Content
Source link
Name
8+9 =