Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
practicecode
/* * A better version of the TP6 C1 Program, using ArrayList * More logical and no more code duplication */ import java.util.ArrayList; import java.util.Iterator; import java.util.Arrays; import java.util.List; import java.util.Set; import java.util.HashSet; class Rextester { public static void main(String args[]){ ArrayList<String> list= new ArrayList<String>(); list.add("subh"); list.add("subh1"); list.add("subh2"); list.add("subh3"); ArrayList<String> list1= new ArrayList<String>(); list1.add("subh"); list1.add("subh5"); list1.add("subh2"); list1.add("subh6"); for(Iterator<String> itr1=list.iterator() ;itr1.hasNext();){ for(Iterator<String> itr2=list1.iterator() ;itr2.hasNext();){ if((itr1.next()).equals(itr2.next())){ System.out.println(itr1.next() +" "+ itr2.next()); } } } String requestObject="121,122,123,121,122,123,121,122,123,121,122,123"; List<String> numList =new ArrayList<String>(Arrays.asList(requestObject.split(","))); Set<String> uniqueSet= new HashSet<String>(); List<String> finalList = new ArrayList<String>(); for(String uniquelist : numList){ if(uniqueSet.add(uniquelist)){ finalList.add(uniquelist); } } System.out.println("unique value :" +finalList); /*Iterator<String> itr = list.iterator(); while(itr.hasNext()){ System.out.println(itr.next());*/ /*for(String li : list){ System.out.println(li);*/ //} } }
run
|
edit
|
history
|
help
0
Alumnos Java con Input
2.C
JAVA # Klavyeden Girilen cümlelerin en uzununu bulma
Count and Say
4.a
program
vampires number Eckel B. Thinking in Java
piglatin
CSV Parser
extends