07 May 2019

#JavaSolved : List of Sorted Unique Words

بِسْمِ اللّهِ الرَّحْمَنِ الرَّحِيْمِ
اللهم صل على محمد وآل محمد
السَّلاَمُ عَلَيْكُمْ وَرَحْمَةُ اللهِ وَبَرَكَاتُه




Question : 



Codes : 

import java.util.*;
public class Soalan2 {
public static ArrayList<String> removeDuplicates(List<String> myString){
ArrayList<String> newList =new ArrayList<String>();
for(String element : myString) {
if(!newList.contains(element)) {
newList.add(element);
}
}
return newList;
}

public static void main(String[] args) {
// TODO Auto-generated method stub
List<String> myString = new ArrayList<String>();
Scanner in = new Scanner(System.in);
String passage = in.nextLine();
StringTokenizer st = new StringTokenizer(passage);
while(st.hasMoreTokens()){
String nextT = st.nextToken();
nextT = nextT.trim();
String delims = "\\W+";
String[] words = nextT.split(delims);
for(int i=0; i<words.length; i++){
myString.add(words[i]);
}
}
ArrayList<String> newList = removeDuplicates(myString);
Collections.sort(newList);
System.out.println(newList);
in.close();
}
}


اللهم صل على محمد وآل محمد
(Allahumma salli 'ala Muhammad wa ali Muhammad)
سُبْحَانَ اللّهِ وَ بِحَمْدِهِ ، سُبْحَانَ اللّهِ الْعَظِيمِ
(SubhanAllahi wa biHamdihi, SubhanAllahil adzim)
سبحانك اللهم وبحمدك أشهد ان لا إله إلا أنت أستغفرك وآتوب إليك
(Subhanakallahumma wabihamdika asyhadu allaailaaha illa anta astaghfiruka wa atuubu ilaika)

No comments:

Post a Comment