Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main;
- import java.lang.reflect.InvocationTargetException;
- import java.util.ArrayList;
- import java.util.List;
- import java.util.stream.Collectors;
- public class App {
- public static void main(String[] args) throws NoSuchMethodException, SecurityException, InstantiationException,
- IllegalAccessException, IllegalArgumentException, InvocationTargetException {
- List<String> list = new ArrayList<>();
- list.add("a");
- list.add("1");
- list.add("b");
- list.add("2");
- list.add("c");
- list.add("3");
- list.add("d");
- list.add("4");
- list.add("e");
- list.add("5");
- list.add("f");
- Entity entity = (Entity) Entity.class.getConstructors()[0]
- .newInstance(list.stream().map(str -> canParse(str) ? Integer.parseInt(str) : str)
- .collect(Collectors.toList()).toArray(new Object[] {}));
- System.out.println(entity);
- }
- public static boolean canParse(String string) {
- try {
- Integer.parseInt(string);
- return true;
- } catch (NumberFormatException nfe) {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement