Java Array

Declaring Array

int[] ia = new int[3];
ia[0] = 9;
ia[1] = 8;
ia[2] = 7;

Char Array To String

char[] ca = {'a', 'p', 'p', 'l', 'e'};
String s = String.valueOf(ca);
System.out.println(s);

Array Sort

String[] fruits = {"pear", "apple", "banana", "orange"};
Arrays.sort(fruits);
for(String fruit:fruits){
System.out.println(fruit);
}

Array List Sort

ArrayList<String> fruits = new ArrayList<String>();
fruits.add("orange");
fruits.add("pear");
fruits.add("apple");
fruits.add("banana");
Collections.sort(fruits);
System.out.println(fruits);
# size
System.out.println(fruits.size()); # 4
# get item 0
System.out.println(fruits.get(0)); # apple

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Kevin FOO

Kevin FOO

A software engineer, a rock climbing, inline skating enthusiast, a husband, a father.