how to create dynamic string array in java
ArrayList<String> mylist = new ArrayList<String>();
mylist.add(mystring); //this adds an element to the list.
how to create dynamic string array in java
ArrayList<String> mylist = new ArrayList<String>();
mylist.add(mystring); //this adds an element to the list.
dynamic array in java
import java.util.ArrayList;
public class Main {
public static void main(String[] args) {
ArrayList<Integer> arr=new ArrayList<Integer>(10);
for(int i =0;i<12;i++){
arr.add(i);
System.out.println("VAlUE" + arr.get(i));
System.out.println("SIZE" + arr.size());
}
}
}
// Dynamic nature means even if we initialize the array with
// a lesser size but at run time we need a greater size.
dynamic array in java
import java.util.Arrays;
public class DynamicArray{
private int array[];
// holds the current size of array
private int size;
// holds the total capacity of array
private int capacity;
// default constructor to initialize the array and values
public DynamicArray(){
array = new int[2];
size=0;
capacity=2;
}
// to add an element at the end
public void addElement(int element){
// double the capacity if all the allocated space is utilized
if (size == capacity){
ensureCapacity(2);
}
array[size] = element;
size++;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us