String [] Letters = {
    "a", ...... , "z",
};    

new ArrayList<String> (Arrays.asList(Letters));

Am currently using the above code, which I believe it creates an ArrayList from the Array call Letters(Please correct me if I'm wrong). I need to know how to add a new String into the ArrayList. Any help would be greatly appreciated, thank you.

share|improve this question
feedback

3 Answers

up vote 2 down vote accepted

Use add:

List<String> list = new ArrayList<String> (Arrays.asList(letters));
// Java naming convention - variables start with lower case ^^
list.add("some new string");
share|improve this answer
thanks for your help. I'm just wondering, wouldn't the system be wasting memories on creating an extra list of array from letters[]? from what I know, new ArrayList<String> (Arrays.asList(Letters)); actually convert letter[] into and arrayList right? or am I wrong on that? – edtylerpro Apr 23 at 9:18
1  
No, it initializes a new arraylist with the content of the array. – Binyamin Sharet Apr 23 at 9:19
if ArrayList<String> (Arrays.asList(Letters)); is initiating a new arraylist what does List<String> list = new ArrayList<String> (Arrays.asList(letters)); do? it seems to me that it's initiating it again. – edtylerpro Apr 23 at 9:23
the same, only assigning the arraylist to a variable, so you can refer to it later, you can use ArrayList<String> list = new ArrayList<String> (Arrays.asList(letters)); – Binyamin Sharet Apr 23 at 9:24
=D I see. thanks for your help and explanation! – edtylerpro Apr 23 at 9:27
feedback

You could use List.add method

List myList = new ArrayList<String> (Arrays.asList(Letters));
myList.add(myString);
share|improve this answer
thanks for helping – edtylerpro Apr 23 at 9:24
feedback

Are you talking about,

String [] Letters = {
    "a", ...... , "z",
};    

ArrayList<String> arrayList = new ArrayList<String> (Arrays.asList(Letters));
arrayList.add("My String");

?

share|improve this answer
thank you for your help. – edtylerpro Apr 23 at 9:19
feedback

Your Answer

 
or
required, but never shown
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.