Posted By: Anonymous
I am new in Java so I need little help
String  scripts = new String  ("test3","test4","test5");
and I want to add new strings ( string1,string2) to this array ( scripts) for examples
String string1= " test1" String string2 = "test2"
I want to add the new string not in the init but in later phase
How I can do it ?
You cannot resize an array in java.
Once the size of array is declared, it remains fixed.
Instead you can use
ArrayList that has dynamic size, meaning you don’t need to worry about its size. If your array list is not big enough to accommodate new values then it will be resized automatically.
ArrayList<String> ar = new ArrayList<String>(); String s1 ="Test1"; String s2 ="Test2"; String s3 ="Test3"; ar.add(s1); ar.add(s2); ar.add(s3); String s4 ="Test4"; ar.add(s4);