• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown


Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
here I have taken some Strings(FirstName<space>SecondName)
I want to sort it by Second list plz help me I am giving the code here. This program sorts on FirstName
import java.util.*;
class TComp implements Comparator{
public int compare(Object a, Object b){
int i, j, k;
String aStr, bStr;
aStr = (String) a;
bStr = (String) b;
i = aStr.indexOf('n');
j = bStr.indexOf('n');
System.out.println("i = "+i+"and j = "+j);
//System.out.println("i = "+i+"and j = "+j);
return aStr.compareTo(bStr);}
return k;
public class TreeMapDemo2{
public static void main(String args[]){
TreeMap tm = new TreeMap();
tm.put(" Sunil Bmar", new Double(3000));
tm.put(" DineshAmar", new Double(100000));
tm.put(" Ravi Chandwani",new Double(2000));
tm.put(" Amit Kumar",new Double(1000));
tm.put(" Bhushan Vasvani",new Double(5000));
tm.put(" Kishan Ratnani",new Double(4000));
Set set = tm.entrySet();
Iterator itr = set.iterator();
Map.Entry me = (Map.Entry)itr.next();
System.out.print(me.getKey()+ ":" );
double balance = ((Double)tm.get("Sunil kumar")).doubleValue();
tm.put("Sunil kumar",new Double(balance + 1000));
System.out.println("Sunil kumar's new balance : "+tm.get("Sunil kumar"));
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Since you posted this same question in Java in General (Advanced), I'm closing the topic here. Please don't post the same question in mutilple forums - it is a waste of time for people to pend time replying to this when it's already been answered elsewhere. Thanks.
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic