Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.google.common.collect.ArrayListMultimap;
- import com.google.common.collect.ListMultimap;
- import java.util.*;
- import java.util.stream.Collectors;
- import java.util.stream.IntStream;
- /**
- * Created by isakow on 03.03.2017.
- */
- public class Vikhorev {
- public static void main(String[] args) {
- int[] array = new Random().ints(10, 0, 5).toArray();
- Set<Integer> set = IntStream.of(array).boxed().collect(Collectors.toSet());
- List<Integer> list = new ArrayList<>();
- list.addAll(set);
- list.addAll(set);
- Collections.shuffle(list);
- // list.add(new Random().nextInt(list.size()), 5);
- list.add(new Random().nextInt(list.size()), 6);
- // list.add(new Random().nextInt(list.size()), 7);
- System.out.println("Массив парных значений рандомный + непаное(ые) в случайном месте: " + list);
- /**
- * use Multimap
- */
- ListMultimap<Integer, Object> lmm = ArrayListMultimap.create();
- list.forEach(l -> lmm.put(l, new Object()));
- System.out.print("Multimap: ");
- for (Integer integer : list) {
- List<Object> element = lmm.get(integer);
- if (element.size() == 1) {
- System.out.print(integer + " " );
- }
- }
- System.out.println();
- /**
- * use XOR
- */
- for (int i = 0; i < list.size() - 1; i++) {
- list.set(i + 1, list.get(i) ^ list.get(i + 1));
- }
- System.out.println("XOR: " + list.get(list.size()-1));
- }
- }
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava-collections</artifactId>
- <version>r03</version>
- </dependency>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement