Write a java program to get a string of words and print the numbers of each word count in descending order

Answer Posted / prash

class WordCount{

public List list;
public static void main(String[] args) {
System.out.println(args[0]);
List arr = Arrays.asList(args);
Iterator it = arr.iterator();
List l = new ArrayList();
while (it.hasNext()) {
String s = (String) it.next();
System.out.println(s);
l.add(s.length());
}
Collections.sort(l);
Collections.reverse(l);
}
}

Is This Answer Correct ?    8 Yes 10 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why is the main method declared static?

577


How do you execute a thread in java?

499


Is treeset sorted in java?

572


What is the size of an array?

545


What is an immutable class?

608






What is difference between array and vector?

524


What type of language is java?

536


What are bind parameters?

541


What is finalize()? Is finalize() similar to a destructor?

534


Which class represents the socket that both the client and server use to communicate with each other?

565


What is immutable in java?

537


What is meant by class loader? How many types are there? When will we use them?

497


What is generic type?

564


Why java is considered as platform independent?

586


Can we overload the constructors?

555