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

--

--

--

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

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Noob’s intro to Algorithms 101

Implement an Stripe payment flow using NestJs & mongodb

Summon the JSON 3rd Top Trending Card Game

Part 3: simplr-forms — declarative forms for React . First e2e flow, FormStore.ToObject()

📦 How to publish your package on npm

Five Steps to Write an Excellent “parseUrl” Function

Kickoff a React project: CRA, Next.js or Gatsby?

Avoid ‘return’ sonar issues in JavaScript

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.

More from Medium

Java Optional

Inheritance in Java

Java vs C++ Differences

Arrays and ArrayList in Java