1 getting the Project absolute path
String Path ="://"":" + Request.getserverport () " / ";
2 Ordering of lists in Java
The first method is to implement the comparable interface in the list object, and the code is as follows:
PublicClass Person implements Comparable<person>{PrivateString name;PrivateInteger order;/** * @return The name*/PublicString GetName () {ReturnName }/** * @param name * The name to set*/PublicvoidSetName (String name) {THIS.name =Name }/** * @return The Order* /public Integer GetOrder () { return order;} /* * * @param order * The order to set * /public void Setorder (Integer order) { This.order =< c12> order; } @Override public int compareTo (person arg0) { return this. GetOrder (). CompareTo ( Arg0.getorder ()); } }
Test examples
PublicStaticvoidMain (string[] args) {list<person> ListA =New arraylist<person>(); person P1 =NewPerson (); person P2 =NewPerson (); Person P3 =NewPerson (); P1.setname ("Name1 "); P1.setorder (1 "name2" ); P2.setorder (2 "name3" ); P3.setorder (3for (person P:lista) {system.out.println (P.getname ());}
The second method is to overload the Collections.sort method with the following code:
PublicClassperson {PrivateString name;PrivateInteger order;/** * @return The name*/PublicString GetName () {ReturnName }/** * @param name * The name to set*/public void setName (String name) { this.name = name;} /* * @return The ORDER * /public Integer GetOrder () { return order;} /* * * @param order * The order to set * /public void Setorder (Integer order) { This.ord ER = Order;}}
PublicStaticvoidMain (string[] args) {list<person> ListA =New arraylist<person>(); person P1 =NewPerson (); person P2 =NewPerson (); Person P3 =NewPerson (); P1.setname ("Name1"); P1.setorder (1); P2.setname ("Name2"); P2.setorder (2); P3.setname ( "name3" Span style= "color: #000000;" >); P3.setorder (3new comparator<person> {public int compare ( Person arg0, person arg1) {return Arg0.getorder (). CompareTo (Arg1.getorder ()); } }); for (person P:lista) {system.out.println (P.getname ());}
The results of two executions are sorted in ascending order according to the order of the person object.
The results of the two executions were: Name1name2name3
Java Learning Summary