简体   繁体   中英

array manipulation in java using arraylist

I am trying to solve one of the following interview problem :

  1. Declare an array/list consisting of 26 alpha values, one for each letter of the alphabet.
  2. Iteratively scan the list for vowels, removing each vowel from this first list and putting it on a second list.
  3. Concatenate all elements of each list into two scalar variables (one for vowels and one for consonants), while also adding a comma between consecutive elements.
  4. Print the values of the two variables on the screen.

I did the first part as follows:

public static void main(String args[]){




 List<String> strings = new ArrayList<String>();
    Collections.addAll(strings,"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z");

    for (String str : strings)
    System.out.println(str);

}

I think I may not have understood the problem properly, the second point is talking about two lists where as in the first part, it only talks about creating one list of alphabets. Please let me know if I haven't understood something from the problem? Does combining values into two scalar variables as mentioned in third point makes sense?

From googling, I've found that a scalar variable is a variable that only has one value at a time.

I believe that part 2 assumes that you create another ArrayList object to hold the vowels so at part 4 you should have two strings: one that contains all the consonants and one that contains all the vowels.

edit: Can't comment because I'm a new member.
In this case a scalar variable would just be a String object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM