function readOnly(count){ }
Don't have an account?
Search for an answer or ask a question of the zone or Customer Support.
You need to sign in to do that
Sign in to start searching questions
Signup for a Developer Edition
Sign in to start a discussion
I'am able to sort my list with .sort() it is a string field but the results are
1
2
3
4
41
43
44
5
TTO
I need it to be
Any help would be greatly appreciated.
Hi, Please use below logic. I tested and it works fine.List<String> stringLst = new List<String>();stringLst.add('1');stringLst.add('2');stringLst.add('3');stringLst.add('4');stringLst.add('41');stringLst.add('43');stringLst.add('44');stringLst.add('5');stringLst.add('TTO');List<String> newStringLst = new List<String>();List<Integer> newIntegerLst = new List<Integer>();Integer temp = null;for (Integer i =0; i < stringLst.size() ; i ++) { System.debug('stringLst' + i + ' : ' + stringLst[i]); try { temp = Integer.ValueOf(stringLst[i]); newIntegerLst.add(temp); } catch (Exception e) { newStringLst.add(stringLst[i]); }}system.debug('-------------------------------------');newIntegerLst.sort();newStringLst.sort();stringLst.clear();for (Integer i =0; i < newIntegerLst.size() ; i ++) { stringLst.add(String.ValueOf(newIntegerLst[i]));}stringLst.addall(newStringLst);for (Integer i =0; i < stringLst.size() ; i ++) { System.debug('stringLst' + i + ' : ' + stringLst[i]);}Thanks & Regards,Vivek V.
I need a little help here. I am displaying documents from a website on VF Page. The order it is displayed is ascending.
I want to display it in descending order. I am using sort() method.
I get following error
Method does not exist or incorrect signature: [String].sort()
Here is my code
public void createDocuments(JSONParser parser) { documentList = new List<Document>(); Document doc = new Document(); Integer position = 0; while (parser.nextToken() != null) { if (parser.getCurrentToken() == JSONToken.START_OBJECT ||parser.getCurrentToken() ==JSONToken.END_OBJECT ) { if(doc.title != null)// && doc.url != null && doc.rating != null && doc.filetype != null && doc.id != null && doc.description != null) { doc.position = position; position++; documentList.add(doc); doc = new Document(); } } if (parser.getCurrentToken() == JSONToken.FIELD_NAME) { if(parser.getText() == 'title') { parser.nextToken(); doc.title = parser.getText(); } if(parser.getText() == 'id') { parser.nextToken(); doc.id = parser.getText(); system.debug('DDDDD'+doc.id); String sortid = doc.id.sort(); docIdsList.add(doc.id); }
Hi,
Please use below logic. I tested and it works fine.
List<String> stringLst = new List<String>();
stringLst.add('1');
stringLst.add('2');
stringLst.add('3');
stringLst.add('4');
stringLst.add('41');
stringLst.add('43');
stringLst.add('44');
stringLst.add('5');
stringLst.add('TTO');
List<String> newStringLst = new List<String>();
List<Integer> newIntegerLst = new List<Integer>();
Integer temp = null;
for (Integer i =0; i < stringLst.size() ; i ++) {
System.debug('stringLst' + i + ' : ' + stringLst[i]);
try {
temp = Integer.ValueOf(stringLst[i]);
newIntegerLst.add(temp);
} catch (Exception e) {
newStringLst.add(stringLst[i]);
}
}
system.debug('-------------------------------------');
newIntegerLst.sort();
newStringLst.sort();
stringLst.clear();
for (Integer i =0; i < newIntegerLst.size() ; i ++) {
stringLst.add(String.ValueOf(newIntegerLst[i]));
}
stringLst.addall(newStringLst);
for (Integer i =0; i < stringLst.size() ; i ++) {
System.debug('stringLst' + i + ' : ' + stringLst[i]);
}
Thanks & Regards,
Vivek V.
All Answers
Hi,
Please use below logic. I tested and it works fine.
List<String> stringLst = new List<String>();
stringLst.add('1');
stringLst.add('2');
stringLst.add('3');
stringLst.add('4');
stringLst.add('41');
stringLst.add('43');
stringLst.add('44');
stringLst.add('5');
stringLst.add('TTO');
List<String> newStringLst = new List<String>();
List<Integer> newIntegerLst = new List<Integer>();
Integer temp = null;
for (Integer i =0; i < stringLst.size() ; i ++) {
System.debug('stringLst' + i + ' : ' + stringLst[i]);
try {
temp = Integer.ValueOf(stringLst[i]);
newIntegerLst.add(temp);
} catch (Exception e) {
newStringLst.add(stringLst[i]);
}
}
system.debug('-------------------------------------');
newIntegerLst.sort();
newStringLst.sort();
stringLst.clear();
for (Integer i =0; i < newIntegerLst.size() ; i ++) {
stringLst.add(String.ValueOf(newIntegerLst[i]));
}
stringLst.addall(newStringLst);
for (Integer i =0; i < stringLst.size() ; i ++) {
System.debug('stringLst' + i + ' : ' + stringLst[i]);
}
Thanks & Regards,
Vivek V.
I need a little help here. I am displaying documents from a website on VF Page. The order it is displayed is ascending.
I want to display it in descending order. I am using sort() method.
I get following error
Method does not exist or incorrect signature: [String].sort()
Here is my code