Answer the question
In order to leave comments, you need to log in
How to cast ArrayList to List?
Good afternoon!
The situation is as follows. There is a result of one module in the form
static public ArrayList<Pair<String, String>> words = new ArrayList<>();
public List <Lexeme> lexemeList
public class Lexeme {
LexemeTypes type;
String value;
public Lexeme(LexemeTypes type, String value) {
this.type = type;
this.value = value;
}
public Lexeme(LexemeTypes type, Character value) {
this.type = type;
this.value = value.toString();
}
public Lexeme(LexemeTypes type, Integer value) {
this.type = type;
this.value = value.toString();
}
@Override
public String toString() {
return "Lexeme{" +
"value='" + value + '\'' +
", type=" + type +
'}';
}
Answer the question
In order to leave comments, you need to log in
Something like:
List<Lexeme> result=Lexemes.words.stream().map(
pair -> new Lexeme(pair.getKey(), pair.getValue())
).collect(Collectors.toList());
List<Lexeme> result=Lexemes.words.stream().map(
pair -> new Lexeme(LexemeTypes.valueOf(pair.getKey()), pair.getValue())
).collect(Collectors.toList());
Use Stream API:
words.map(pair -> /* тут преобразуй пару в лексему по твоим правилам */).collect(Collectors.toList());
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question