Return-Path: Delivered-To: apmail-commons-user-archive@www.apache.org Received: (qmail 86415 invoked from network); 2 Apr 2008 21:32:02 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Apr 2008 21:32:02 -0000 Received: (qmail 6833 invoked by uid 500); 2 Apr 2008 21:31:59 -0000 Delivered-To: apmail-commons-user-archive@commons.apache.org Received: (qmail 6769 invoked by uid 500); 2 Apr 2008 21:31:59 -0000 Mailing-List: contact user-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Jakarta Commons Users List" Delivered-To: mailing list user@commons.apache.org Received: (qmail 6760 invoked by uid 99); 2 Apr 2008 21:31:58 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Apr 2008 14:31:58 -0700 X-ASF-Spam-Status: No, hits=-0.0 required=10.0 tests=SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of agile.aspect@gmail.com designates 64.233.170.188 as permitted sender) Received: from [64.233.170.188] (HELO rn-out-0910.google.com) (64.233.170.188) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 02 Apr 2008 21:31:17 +0000 Received: by rn-out-0910.google.com with SMTP id a43so1873627rne.10 for ; Wed, 02 Apr 2008 14:31:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:reply-to:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:from; bh=sQ9hBCEJHbE/gbRpk4oKlrMeMKomG/czGWjfezGp1jw=; b=ROCAKsEgNg+usOC6s8VE1dsrtfOFAdEXsivC6pG1vuJ3am4FXiUD+o0XIEbEo/QKTyFqKMgchn4w3O8ltfZoRng/fFtV8CwIpxa8PfDRB0K0tIDQmHRWeDhC/TXrP0Gq6+7M3nnoNfXPH+yEy/JCHrTKehd2o2HreT220a1kHb8= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=message-id:date:reply-to:user-agent:mime-version:to:subject:references:in-reply-to:content-type:content-transfer-encoding:from; b=FBRB9oUHbAHCQX7AemUAdsNToeKB+j+oBj6a9ozYusQaKPh5YzvESDSIscRL1mAcuNoL8iaZ8ZJuAfmmZgTYnkOcjHnctwxhYvUUc5FibONuuuKN6XpmJBC40uVtTiI91uGesTGWNKwDqbjBTTJYt+/9Q2dnYUnWG0n53SEUmdw= Received: by 10.114.88.1 with SMTP id l1mr15730387wab.126.1207171887917; Wed, 02 Apr 2008 14:31:27 -0700 (PDT) Received: from ?10.0.0.10? ( [67.164.31.129]) by mx.google.com with ESMTPS id m27sm5615233wag.50.2008.04.02.14.31.26 (version=TLSv1/SSLv3 cipher=RC4-MD5); Wed, 02 Apr 2008 14:31:27 -0700 (PDT) Message-ID: <47F3FB8D.7090805@GMail.COM> Date: Wed, 02 Apr 2008 14:33:01 -0700 Reply-To: Agile.Aspect@GMail.COM User-Agent: Thunderbird 2.0.0.12 (X11/20080213) MIME-Version: 1.0 To: Jakarta Commons Users List Subject: Re: [Collections] "For each pair" iterator References: <0423B15811282F4A951430224A59E0CA33A2B3@FRVELSMBS24.ad2.ad.alcatel.com> In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit From: Agile Aspect X-Virus-Checked: Checked by ClamAV on apache.org Hi - here you go. Note, Set is an interface so I implement it with 3 different concert classes, namely HashSet LinkedHashSet TreeSet using generics. If you're not familiar with generics, then remove all occurences of Hope this helps. --------------------------------------------------------------------------------------------------------- import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; import java.util.TreeSet; public class MySet { public static void test(Set set, String string){ set.add(new Integer(1)); set.add(new Integer(4)); set.add(new Integer(2)); set.add(new Integer(3)); System.out.println(string+":"); Object[] array=new Object[set.size()]; array=set.toArray(); for(int i=0; i i) { System.out.println(array[i]+","+array[j]); } } } } public static void main(String args[]){ test(new HashSet(),"HashSet"); test(new TreeSet(),"TreeSet"); test(new LinkedHashSet(),"LinkedHashSet"); } } Pedro Pedruzzi wrote: > Hi, > > What I'd like to do is iterate through each subset of size 2 of a Set. > > Example: > > My set is: S = {1,2,3,4} > I'd like to iterate throught every one of these subsets: > {1,2}, {1,3}, {1,4}, {2,3}, {2,4} and {3,4}. > > > -- Article. VI. Clause 3 of the constitution of the United States states: "The Senators and Representatives before mentioned, and the Members of the several State Legislatures, and all executive and judicial Officers, both of the United States and of the several States, shall be bound by Oath or Affirmation, to support this Constitution; but no religious Test shall ever be required as a Qualification to any Office or public Trust under the United States." --------------------------------------------------------------------- To unsubscribe, e-mail: user-unsubscribe@commons.apache.org For additional commands, e-mail: user-help@commons.apache.org