String str = " qadadsadsa";
int[] ints = str.chars().toArray(); // есть легкий способ
System.out.println(ints); // байты
// по другим вопросам
ArrayList<String> list = new ArrayList<String>(){{
this.add("5");
this.add("5");
this.add("4");
this.add("8");
this.add("9");
this.add("1");
this.add("6");
}};
List<String> strings = list
.stream()
.filter(f -> f.equals("5")) // все, что равно 5
.collect(Collectors.toList()); // собрать результат в list
ArrayList<M> list2 = new ArrayList<M>(){{
this.add(new M(1,1));
this.add(new M(2,2));
this.add(new M(3,3));
this.add(new M(4,4));
this.add(new M(5,5));
this.add(new M(6,6));
this.add(new M(7,7));
}};
List<M> res = list2.stream()
.filter(f -> f.b > 3) // только те результаты, где b > 3
.limit(2) // ограничить до двух элементов (первые 2)
.collect(Collectors.toList()); // собрать результат в list
List<Integer> collect = res
.stream()
.map(m -> m.a) // брать только значения а
.collect(Collectors.toList()); // собрать результат в list
public class M {
public int a, b;
public M(int a, int b) {
this.a = a;
this.b = b;
}
@Override
public String toString() {
return "M{" +
"a=" + a +
", b=" + b +
'}';
}
}
str.getBytes()
? – Nofate♦ 20 сен '16 в 10:36