I came across a code snippit from my textbook with a : symbol.

for  (String arg : arg){
    System.out.println(arg);
}

I'd like to know what that : is, and what function it serves.

Thanks,

Probably a typo - should be: for (String arg : args){

It's a "for each" loop, introduced in Java 1.5. You read it as
"for each String arg in args"
It sets arg to the first element of args and executes the following println code, it then sets it to the second element, executes the code again (etc etc). It's roughly equivalent to, but much neater than

String arg;
for (int i = 0; i < args.length; i++ ) {
  arg = args[i];
  System.out.println(arg);
}

It also works with any kind of Collection eg ArrayList in exactly the same way, and avoids the complexity and pitfalls of Iterators.

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.