You need to sign in to do that
Don't have an account?
kavya mareedu
Hello! I want to write a program to identify the duplicate values. I have a myList with all the list values and newList with set values. In set values the duplicates of list were removed. Compare the list and set,display the cmmn values in othr list
public class Colors {
public string colors;
public List<string> myList;
public set<string> newList;
public colors(){
myList=new List<string>{'Blue','Blue violet','Red','Green','Dark Red','Light Red','Orange Red','Coral Red',
'Forest Green','Hunter Green','Sage Green','Black','Red','Orange','Yellow','Blue violet'};
system.debug(myList.size());
newList=new set<string>();
newList.addAll(myList);
system.debug(newList);
}
public string colors;
public List<string> myList;
public set<string> newList;
public colors(){
myList=new List<string>{'Blue','Blue violet','Red','Green','Dark Red','Light Red','Orange Red','Coral Red',
'Forest Green','Hunter Green','Sage Green','Black','Red','Orange','Yellow','Blue violet'};
system.debug(myList.size());
newList=new set<string>();
newList.addAll(myList);
system.debug(newList);
}
My understanding is you want to create a list of comman string among the list and set of string.
You can try something like this: Hope this helps!
so basicallly you will use a for loop that cycles through one list and another for loop that cycles through the other list to compare values:
(add this after your code and befer the end curly-bracket of your class.
Hey! I wrote the whole code but I am not able to execute it
When I am trying to create an object in the anonymous window and call the method. It says: Line: 2, Column: 3
Method does not exist or incorrect signature: void colors() from the type Colors
Help me out:
public class Colors {
public string colors;
public List<string> myList;
public set<string> newList;
public List<String> commList;
public colors(){
myList=new List<string>{'Blue','Blue violet','Red','Green','Dark Red','Light Red','Orange Red','Coral Red',
'Forest Green','Hunter Green','Sage Green','Black','Red','Orange','Yellow','Blue violet'};
system.debug(myList.size());
system.debug(myList);
system.debug(myList.get(9));
newList=new set<string>();
commList = new List<String>();
for(String str : myList) {
for(String st : newList) {
if(str == st)
commList.add(str);
}
}
system.debug(commList);
}
public void sort(){
myList.sort();
system.debug(myList);
}
public void reverseorder(){
List<String> finalList = new List<String>();
for(Integer i = myList.size()-1; i>=0;i--)
{
finalList.add(myList.get(i));
}
System.debug('Check the Order -->'+finalList);
}
}
Colors c=new Colors();
c.colors();
Please let me know how should I fix this error.
I am just 4 months old with this development part.
It would be great if you make me understand this
There is also the problem that the newList doesn't have any values when you start looking for duplicates.