简体   繁体   中英

How can I convert a String array to a different Class ArrayList in Java

I'm trying to figure out how to write logic to convert an array of string into an ArrayList weekday object

String[] weekdays = request.getParameterValues("weekday");

I've made my ArrayList weekday2 the length of my String[] weekdays.

ArrayList<WeekDay> weekdays2 = new ArrayList<WeekDay>(weekdays.length);

I know there is a way to utilize enums, and that's what I'm trying to do.

for (int i = 0; i < weekdays.length; i++) {
            weekdays2.add(new WeekDay().valueOf(weekdays2, weekdays));
        }

I know I'm definitely missing something.

error:

The method valueOf(Class<T>, String) in the type Enum<WeekDay> is not applicable for the arguments (ArrayList<WeekDay>, String[])

Code to get list of WeekDay may be such:

    for (int i = 0; i < weekdays.length; i++) {
        weekdays2.add(WeekDay.valueOf(weekdays[i]));
    }

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