- 浏览: 76764 次
文章分类
- 全部博客 (89)
- web service (9)
- subversion (1)
- JBOSS (3)
- interview (23)
- jQery (2)
- ExtJs (0)
- Axis (0)
- Design pattern (3)
- Agile (2)
- mutithread (0)
- Core Java (24)
- programming methods (1)
- SSH (7)
- jee design (1)
- OO (4)
- books (8)
- other (1)
- JSF (7)
- seam (2)
- Weblogic (4)
- JPA (1)
- ADF (1)
- Spring (5)
- Tomcat (1)
- DWR (2)
- JEE (3)
- Servlet (1)
- EJB (1)
- JDBC (3)
最新评论
-
iloveflower:
呵呵。好好学习。。。。。。。。。。。。
java 读书 -
Eric.Yan:
看了一点,不过是电子版的……你这一说到提醒我了,还要继续学习哈 ...
java 读书
A common mistake for a beginner to Java is to try and write some more or less complex method for sorting an array when in fact it can be done with just one line of code.
The Arrays class has a static method called sort which exists in many overloaded versions so you can pass in an array of any primitive type, or pass in an array of Strings or other Objects.
Since it is the reference of the array that is passed to the sort method nothing needs to be returned from it, the array is altered through the reference.
The example below shows two nearly identical methods, one that sorts an int array, and one that sorts an array of Strings.
The Arrays class has a static method called sort which exists in many overloaded versions so you can pass in an array of any primitive type, or pass in an array of Strings or other Objects.
Since it is the reference of the array that is passed to the sort method nothing needs to be returned from it, the array is altered through the reference.
The example below shows two nearly identical methods, one that sorts an int array, and one that sorts an array of Strings.
import java.util.Arrays; /** * * @author javadb.com */ public class Main { /** * Example method for sorting an int array */ public void sortIntArray() { int[] arrayToSort = new int[] {48, 5, 89, 80, 81, 23, 45, 16, 2}; Arrays.sort(arrayToSort); for (int i = 0; i < arrayToSort.length; i++) System.out.println(arrayToSort[i]); } /** * Example method for sorting a String array */ public void sortStringArray() { String[] arrayToSort = new String[] {"Oscar", "Charlie", "Ryan", "Adam", "David"}; Arrays.sort(arrayToSort); for (int i = 0; i < arrayToSort.length; i++) System.out.println(arrayToSort[i]); } /** * @param args the command line arguments */ public static void main(String[] args) { Main main = new Main(); main.sortIntArray(); main.sortStringArray(); } } how to reverse a integer 既然都转成了String为什么不用StringBuffer呢 String str = StringBuffer.reverse(String.valueOf(integer)).toString(); return Integer.parseInt(s); 最多多三行解决问题。 public int reverse(int a){ return Integer.parseInt(new StringBuilder(String.valueOf(a)).reverse().toString()); } LinkedList list = ... int size = list.size(); int middle = (size / 2) + (size % 2 == 0 ? 0 : 1) - 1; //index of middle item Object o = list.get(middle); //or ListIterator it = list.listIterator(middle);
发表评论
-
Java Collection summary
2012-06-16 02:40 534Collection:List、Set Map: ... -
When to use Comparable vs Comparator
2012-06-15 00:52 748I have a list of objects I need ... -
Arrays.fill with multidimensional array in Java
2012-06-15 00:09 654How can I fill a multidimension ... -
Immutable objects
2012-06-14 23:49 666Immutable objects are simply ... -
Implementing hashCode; Transaction.java
2012-06-14 23:43 785Below is the syntax highlight ... -
Lazy initialization
2012-06-14 22:48 765http://www.javapractices.com/to ... -
Java各类型转换
2012-06-13 05:25 663各种数字类型转换成字符串型: String s = Str ... -
regular expression
2012-06-13 03:08 4751、Java对反斜线处理的 ... -
string functions
2012-06-13 00:09 786import java.util.*; public c ... -
String array to arraylist
2012-06-13 00:07 538There are some important thing ... -
core java interview summary
2012-06-12 04:11 344http://blog.sina.com.cn/s/blog_ ... -
programming with String
2012-06-12 01:43 522Question: 1) Write code to che ... -
OO Design books -good website
2012-06-07 03:13 658I’m always on the search on goo ... -
Write a String Reverser (and use Recursion!)
2012-06-07 03:03 489Java Interview questions: Write ... -
Java高手必会的要点
2012-05-29 03:28 579http://developer.51cto.com/art/ ... -
How to use getClass().getClassLoader().getResource()
2012-05-29 03:13 1710This is the simplest wat to get ... -
How to override equals method in Java
2012-05-12 02:57 1509Object class holds some very in ... -
Top 30 Programming interview questions
2012-05-12 02:48 874Programming questions are integ ... -
10 example of using ArrayList in Java >>> Java ArrayList Tutorial
2012-05-12 02:37 812ArrayList in Java is most frequ ... -
How to use Comparator and Comparable in Java? With example
2012-05-12 02:21 736Read more: http://javarevisited ...
相关推荐
1. List概述List,就如图名字所示一样,是元素的有序列表 3. ArrayList示例[java] view plain copy public sta
LinkedList<Integer> ab=new LinkedList(); for(int i=0;i;i++) ab.add(i+1); for(;;){ if(ab.size()==0)break;//结束条件 int i=1; while(i!=M){ ab.add(ab.remove());//如果没有报到M这个数字的人将其从...
非常简单的Java LinkedList 应用实例
ArrayList、LinkedList、Vector区别简介。
java LinkedList的添加删除操作 java LinkedList的添加删除操作
Java 中Linkedlist类的源代码Java 中Linkedlist类的源代码Java 中Linkedlist类的源代码Java 中Linkedlist类的源代码
List-LinkedList 单链表就地反转 的代码的一种实现。
LinkedLIst.cpp
使用LinkedList模拟堆栈操作,包括进栈、出栈,入队、出队
LinkedList实践代码,用于学习LinkedList功能,包括二叉树的构建和遍历等。
LinkedList的使用.pdf
List<String> l1=new LinkedList();//使用泛型 //List l1= new LinkedList(); int index=0; //插入元素 l1.add("firstElement"); l1.add("secondElement"); l1.add("thirdElement"); //访问索引 ...
1.List是接口类,ArrayList和LinkedList是List的实现类 2.ArrayList是动态数组(顺序表)的数据结构 3.LinkedList
使用LinkedList类编写程序,用某种集合接口的实现类作存储,实现具有自定义排序功能的包含姓名、年龄、身高、职称等内容的人事信息输入和打印。
和数组一样,LinkedList 也是一种线性数据结构,但它不像数组一样在连续的位置上存储元素,而是通过引用相互链接。 LinkedList 中的每一个元素都可以称之为节点(Node),每一个节点都包含三个项目:其一是元素本身...
LinkedList<String> list = new LinkedList(); list.add("aaa"); list.add("bbb"); list.add("ccc"); /* * public void addFirst(E e)方法 * 将指定元素插入此列表的开头 */ list.addFirst("000...
and see how to use them to implement advanced data structures such as Stack, StackList, Queue, and LinkedList Implement sorting algorithms such as Insertion Sort, Merge Sort, and Quick Sort and ...
Find out about Swift generators and sequences, and see how to use them to implement advanced data structures such as Stack, StackList, Queue, and LinkedList Implement sorting algorithms such as ...
深入解析hashMap底层原理,非常深入的讲解了HashMap和相关的数据的等信息
数据结构,LinkedList在c++的实现,一共有三个头文件:Link.h 、List.h 、LinkedList。