2

I'm new to Java and I can't figure out what the difference between String[] and Array<String> is. And how do I actually count how many entries a String[] Array has? Thanks!

2
  • What's Array<String>? I can't find any Array<T> class in the JDK reference, and my JDK's javac won't let me compile an Array<String> foo; declaration. There's ArrayList<T>, but that's something else entirely. Commented Jul 12, 2011 at 10:21
  • Probably IDE autocompletion gave him the java.lang.reflect.Array class. Commented Jul 12, 2011 at 10:22

3 Answers 3

8

And how do I actually count how many entries a String[] Array has?

if(strArr !=null){
  strArr.length;
}
Sign up to request clarification or add additional context in comments.

Comments

6

String[] - is an array

Array - is a part of reflection API which you shouldn't bother about until you get more experience in java.

String[] a = new String[length]; - is a proper instantiation of array

a.length - returns length of the array

1 Comment

I had to wait 10 Minutes before the system let me do that ;)
2

Main difference: String[] is not resizable.

Length of String[]: use .length property.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.