Back to articles
Java Array Methods That Actually Make Sense
How-ToTools

Java Array Methods That Actually Make Sense

via Dev.to BeginnersManikanta Yarramsetti

Arrays were honestly confusing to me at first. Not the concept — storing multiple values, fine. But all the utility methods scattered across different classes? That took a while to click. Here's what I wish someone had just shown me early on. First, the Two Classes You Need to Know Most array utility methods live in java.util.Arrays — you need to import it. For resizing and dynamic stuff, ArrayList is your friend (but that's a separate topic). import java.util.Arrays ; Okay, let's get into it. The Methods Arrays.sort() — sorts your array in ascending order. Works for numbers and strings. int [] nums = { 5 , 2 , 8 , 1 , 9 }; Arrays . sort ( nums ); // nums is now {1, 2, 5, 8, 9} Arrays.toString() — this one you'll use constantly for debugging. Prints array contents instead of some weird memory address. int [] nums = { 1 , 2 , 3 }; System . out . println ( nums ); // [I@6d06d69c ← useless System . out . println ( Arrays . toString ( nums )); // [1, 2, 3] ← useful Arrays.fill() — fills al

Continue reading on Dev.to Beginners

Opens in a new tab

Read Full Article
0 views

Related Articles