i have an arraylist, that stores objects from a class called prematricula and every object stored has name and province how i can do to pass the name of the province and the method return the names of the students sorted alfabethically...
please if someone can help me....
jaque322
0
Newbie Poster
Recommended Answers
Jump to PostCreate method that will take an ArrayList as an agrument and will have ArrayList as return value. Something along the line of this method showed by masijade in this thread
Jump to PostUse java.lang.Comparable interface and java.util.Arrays class.
Here is sample code:
Emp.java
public class Emp implements Comparable { private String name; private String city; public Emp(){} public Emp(String name,String city) { this.city=city; this.name=name;} public int compareTo(Object p) { Emp a=(Emp)p; return name.compareTo(a.name); } public String getName() …
Jump to PostI am sorry. Which collection class has sort method?
Collections
That is a Class in and of itself, much like Arrays.
All 9 Replies
peter_budo
2,532
Code tags enforcer
Team Colleague
Featured Poster
kvprajapati
1,826
Posting Genius
Team Colleague
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
kvprajapati
1,826
Posting Genius
Team Colleague
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
kvprajapati
commented:
Great eyes!
+3
kvprajapati
1,826
Posting Genius
Team Colleague
peter_budo
2,532
Code tags enforcer
Team Colleague
Featured Poster
masijade
1,351
Industrious Poster
Team Colleague
Featured Poster
jaque322
0
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.