Java tutorial
//package com.java2s; /* * Twittnuker - Twitter client for Android * * Copyright (C) 2013-2014 vanita5 <mail@vanita5.de> * * This program incorporates a modified version of Twidere. * Copyright (C) 2012-2014 Mariotaku Lee <mariotaku.lee@gmail.com> * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import java.util.ArrayList; import java.util.List; public class Main { public static long[] intersection(final long[] array1, final long[] array2) { if (array1 == null || array2 == null) return new long[0]; final List<Long> list1 = new ArrayList<Long>(); for (final long item : array1) { list1.add(item); } final List<Long> list2 = new ArrayList<Long>(); for (final long item : array2) { list2.add(item); } list1.retainAll(list2); return fromList(list1); } public static long[] fromList(final List<Long> list) { if (list == null) return null; final int count = list.size(); final long[] array = new long[count]; for (int i = 0; i < count; i++) { array[i] = list.get(i); } return array; } }