An ArrayList is a dynamic data structure, items can be added and removed from the list.
ArrayList implements List interface it maintains insertion order of element and allow duplicates.
import java.util.ArrayList; public class Demo { public static void main(String[] args) throws IOException { ArrayList<String> myArr = new ArrayList<String>(); myArr.add("one"); myArr.add("two"); myArr.add("threeo"); myArr.add("four"); myArr.add("five"); myArr.add("six"); System.out.println("Enter numbers:"); String name = userInput.readLine(); Integer nameLength = name.length(); if (nameLength == 0) { System.out.println("empty number entered"); return; } Integer vacationIndex = nameLength % myArr.size(); System.out.println(" "+number+", iis "nameLength + " charact+ myArr.get(vacationIndex)); } }
Aryantech india

No comments:
Post a Comment