/**
* Created by puruidong on 2015/4/2.
*/
public class TestDemo {
public static void main(String[] args) {
//记住下面这个一定要用Integer,而不能用int,否则下面判断不了!!!
/*Java 1.8 Version */
//List<Integer>
parse(Arrays.asList(new Integer [] {1,2,3,4,5,6,7,8,9,10})).forEach(System.out::println);
//List<String>
//List<?> lists = parse(Arrays.asList(new String [] {"12","2","3"}));
for (Object os :lists){
System.out.println(os);
}
/*Java 1.7 Version end */
}
private static List<? extends Object> parse(List<? extends Object> list){
if(list.size()==0){
return null;
}
/**/
List<Object> result = null ;
//处理String.
if(list.get(0) instanceof String){
//如果是String则增加一个Hello World到末尾.
result = new ArrayList<>(list);
result.add("hello world");
}else if (list.get(0) instanceof Integer){
//处理Integer
result = new ArrayList<>(list);
result.add(5000000);
/*
* 处理更多的思路是:使用下面的循环遍历出里面的值强转为int.即可.
for (Object os:list){
int rs = (int)os;//或者使用int rs = Integer.valueOf(os.toString());
//其他操作,不要在这里将修改后的值赋给list,否则报错.
}
*/
}
return result ;
}
static <E> List<E> remDup(List<E> list) {
for (E e : list) {
if (e instanceof Integer) {
//TODO
} else if (e instanceof String) {
//TODO
}
}
return null;
}
}
/**
* Created by puruidong on 2015/4/2.
*/
public class TestDemo {
public static void main(String[] args) {
//记住下面这个一定要用Integer,而不能用int,否则下面判断不了!!!
/*Java 1.8 Version */
//List<Integer>
parse(Arrays.asList(new Integer [] {1,2,3,4,5,6,7,8,9,10})).forEach(System.out::println);
//List<String>
//List<?> lists = parse(Arrays.asList(new String [] {"12","2","3"}));
for (Object os :lists){
System.out.println(os);
}
/*Java 1.7 Version end */
}
private static List<? extends Object> parse(List<? extends Object> list){
if(list.size()==0){
return null;
}
/**/
List<Object> result = null ;
//处理String.
if(list.get(0) instanceof String){
//如果是String则增加一个Hello World到末尾.
result = new ArrayList<>(list);
result.add("hello world");
}else if (list.get(0) instanceof Integer){
//处理Integer
result = new ArrayList<>(list);
result.add(5000000);
/*
* 处理更多的思路是:使用下面的循环遍历出里面的值强转为int.即可.
for (Object os:list){
int rs = (int)os;//或者使用int rs = Integer.valueOf(os.toString());
//其他操作,不要在这里将修改后的值赋给list,否则报错.
}
*/
}
return result ;
}
static <E> List<E> remDup(List<E> list) {
for (E e : list) {
if (e instanceof Integer) {
//TODO
} else if (e instanceof String) {
//TODO
}
}
return null;
}
}