“Java -String -Array -Element hinzufügen” Code-Antworten

Java -String -Array -Element hinzufügen

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);
Helpless Hedgehog

Java -Array fügen Sie Element hinzu

// A better solution would be to use an ArrayList which can grow as you need it. 
// The method ArrayList.toArray( T[] a ) 
// gives you back your array if you need it in this form.

List<String> where = new ArrayList<String>();
where.add(element);
where.add(element);

// If you need to convert it to a simple array...

String[] simpleArray = new String[ where.size() ];
where.toArray( simpleArray );
Helpless Hornet

So fügen Sie in Java String zum Array hinzu

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);
Cooperative Caterpillar

Fügen Sie die Zeichenfolge zu Array Java hinzu

in java, once you declared an array you cannot change its size.
so that adding an element to the array is not possible.
you can declare an arraylist, which is the same as array but its resizable.
meaning that you can add or remove at any time and as much you want.
for example:
ArrayList<String> languages = new ArrayList<String>(); 
languages.add("PHP");
languages.add("JAVA");
languages.add("C#");
ArrayList<int> numbers = new ArrayList<int>(); 
numbers.add(9);
numbers.add(14);
numbers.add(2);
Programming Is Fun

Ähnliche Antworten wie “Java -String -Array -Element hinzufügen”

Fragen ähnlich wie “Java -String -Array -Element hinzufügen”

Weitere verwandte Antworten zu “Java -String -Array -Element hinzufügen” auf Java

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen