Learn Java Tutorial for Beginners, Part 11: Arrays of Strings

///Learn Java Tutorial for Beginners, Part 11: Arrays of Strings

Learn Java Tutorial for Beginners, Part 11: Arrays of Strings

FavoriteLoadingAdd to favorites

Get complete courses at
A tutorial on arrays of Strings in Java, plus another way to iterate through an array, and more stuff on the difference between values and references.

source

Java468x60
By |2019-06-03T19:24:00+00:00June 3rd, 2019|Java Video Tutorials|38 Comments

38 Comments

  1. Chris M June 3, 2019 at 7:24 pm - Reply

    Please invest in a better microphone. Thanks for the vid!

  2. Shane White June 3, 2019 at 7:24 pm - Reply

    Thank you for this tutorial. Far be it for me to go off point, you have a very reasuring voice which makes listening and learning easy.

  3. Dawid Gybej June 3, 2019 at 7:24 pm - Reply

    I really like ur voice, it matches perfectly with classic music, this is what makes u better than all the other yt IT tutorials, it's so simple to understand the english u speaking (semplified) and tho can explain it very nicely. Good job man, congrats

  4. theantonlulz June 3, 2019 at 7:24 pm - Reply

    Didn't know the mic has to be put so close to your mouth

  5. SCHRODINGER’S CAT June 3, 2019 at 7:24 pm - Reply

    best CS teacher on the internet. i recommend you to all my classmates for Udemy

  6. Haute Swan June 3, 2019 at 7:24 pm - Reply

    That helped so much. Thank you again.

  7. Ron Harden June 3, 2019 at 7:24 pm - Reply

    Hey John,
    I'm trying to iterate backwards through an array. Can you help with this?
    I've tried dividing by two and moved around the less than 1 problem all over the place. I can only ever get the first two to swap. The problem is just like your coding in the beginning with a set number of elements and a list of the values in the elements. Thank you!!
    code:
    public class Array2 {
    public static void main (String [] args) {
    final int NUM_VALS = 4;
    int[] courseGrades = new int[NUM_VALS];
    int i = 0;

    courseGrades[0] = 7;
    courseGrades[1] = 9;
    courseGrades[2] = 11;
    courseGrades[3] = 10;

    for(i = 0; i < NUM_VALS; ++i){
    System.out.print(courseGrades[i] + " ");
    }
    System.out.println();
    int temp;
    for(i = 0; i < NUM_VALS; ++i){
    temp = courseGrades[NUM_VALS -i -1];
    courseGrades[NUM_VALS -i -1] = courseGrades[i];
    courseGrades[i] = temp;
    System.out.print(courseGrades[i] + " ");

    }
    System.out.println();

    return;
    }
    }

  8. Jesus Huerta Perez June 3, 2019 at 7:24 pm - Reply

    me sirvio mucho,muchas gracias . thank you

  9. Logix June 3, 2019 at 7:24 pm - Reply

    These tutorials you have made are really helpful. 🙂

  10. Lawrius Yucheng June 3, 2019 at 7:24 pm - Reply

    Hi John,

    1. How do I swap values of Array String ?

    2. How to check if all 3pairs of Cards , whose values are Strings in an Array String[] have all been matched , in a Card Matching game?

    thanks

  11. Heat4Life June 3, 2019 at 7:24 pm - Reply

    A little bit stressing but… I'm learnin'.. lol

  12. Tony Montana June 3, 2019 at 7:24 pm - Reply

    Minor nitpick: "null" does not mean "nothing" so much as "unknown" This helps differentiate between an empty "" string vs. a null string

  13. Jair Martinez June 3, 2019 at 7:24 pm - Reply

    exellent tutorial, easy to understand as long as you have the basic begginers knowledge . keep up the great work ! .

  14. Dan Hoang June 3, 2019 at 7:24 pm - Reply

    how would i go about making a method that takes a string parameter that adds this parameter to an array of strings?

  15. Rohan Desilva June 3, 2019 at 7:24 pm - Reply

    Yo you need to spit what ever is in your mouth fham it's scaring the shit outta me

  16. Mateusz G June 3, 2019 at 7:24 pm - Reply

    Thank you very much:)

  17. The gamer June 3, 2019 at 7:24 pm - Reply

    why u make it complex this is not for beginners

  18. The gamer June 3, 2019 at 7:24 pm - Reply

    how colon works?

  19. Goodborn June 3, 2019 at 7:24 pm - Reply

    System.out.print(Arrays.toString('arrays name'));

    If you want to print all the elements without an loop..

  20. Flamo353 June 3, 2019 at 7:24 pm - Reply

    for each String in String[]
    for(String variablename : fruits) {
    //do this stuff
         System.out.println(fruit); //Will loop through every string in the string array "fruits".
    }

  21. monica steffi matchado June 3, 2019 at 7:24 pm - Reply

    how to store each and every array strings in java

  22. pumbas June 3, 2019 at 7:24 pm - Reply

    public class BestTeacher{
    public static void main(String[] args) {

    System.out.println("Thank u for the effort John");

    }
    }

  23. slier81 June 3, 2019 at 7:24 pm - Reply

    i stressed 🙁

  24. Huda BZ June 3, 2019 at 7:24 pm - Reply

    I have a question ?? 
    if i want from the user to insert an unknown number of a string values and keep it in array 
    how can i do this ?? 
    please needing some help to solve my problem 

  25. Brandon Gamer June 3, 2019 at 7:24 pm - Reply

    You lost me when you used the For loop as an example: for (String fruit: fruits). How does Java know the difference between fruit and fruits since I don't see anywhere in your code that defines, 'fruit'. e.g. without the, 's'. Did I miss something?
     (nm Figured it out) 🙂

  26. ThysiosX June 3, 2019 at 7:24 pm - Reply

    1:12 what if I don't know what the words are going to be. Until the user has input them?

  27. Paul Angelo Dasugo June 3, 2019 at 7:24 pm - Reply

    guys can anyone do this???? send it to me when its done

    >>>>>>>>>
    PROBLEM DEFINITION:

    Create a MyCar class and a Lot class that is an array of Car objects, and an application class called LotUser class,
     which uses the other 2 classes.

    Create three separate files called  MyCar.java, Lot.Java, and LotUser.java for the three classes respectively.

    Class specification for the three classes is given below:

    1.

    Class name: MyCar

    Instance variables:

    – a  private instance variable called color of type String to store color of car
    – a  private instance variable called brand of type String to store brand of car;
    – a  private instance variable called status of type  String to store  status of car;

    Methods:
    – a public  Constructor without parameters to initialize the instance variables to null
    – a public Constructor with parameters to initialize the instance variables with the parameter values
    – three public accessor methods to access the private instance variables
    – a public method to display the instance variables

    2.

     Class Name:  Lot 

    Instance Variables:

    – a private instance variable which is an array of cars
    – a private instance variable called color which is a String array containing “red”, “white”, and “blue”
    – a private instance variable called brand which is a String array containing “Ford”, “Chevrolet”, “Chrysler”, and “Porsche”
    – a private instance variable called status which is a String array containing “new” and “used”
    – a private static (class) variable called z initialized to “Welcome to all car lots!”

    Methods:

    – a constructor without parameters which generates a CarLot as a 1000 element array of cars, such that the color of a given 
    car is randomly chosen from the color array mentioned above, the brand of the car is randomly chosen from the brand array
     mentioned above, and the status of the car is always chosen as new
    – one public instance method (non-static) which will return a car from a CarLot instance based on an int parameter from
     a user of the method, where it is assumed that the int is the number of the car in the CarLot (starting at 0)
    – one public static (class) method that will print out the String in the static instance variable z, when called

    3.

    Class Name:  LotUser

    Method:

    public static void main(String args[])- having the following functionality:

    1. Instantiate a CarLot called mylot, and instantiate a CarLot called yourlot.
    2. Print out the welcome message based on an appropriate call to the welcome method.
    3. Count the number of white Fords in each Carlot instance, and the number of red Porshes in each Carlot instance,
     and output the counts

    Required Output:

    Welcome to all car lots!

    The number of white Fords in my lot is: 'number'
    The number of red Porsches in my lot is: 'number'

    The number of white Fords in your lot is: 'number'
    The number of red Porsches in your lot is: 'number'

  28. Ankit Hashia June 3, 2019 at 7:24 pm - Reply

    Hello John, I've been using these videos to get a hold on Java and they have helped a lot.
    I'm thinking about going to the Data Analytics domain. BIG Data and Hadoop, Do you have any videos for that.?

  29. ZuluNation23 June 3, 2019 at 7:24 pm - Reply

    Pull the mic out of your mouth, please.

  30. Bill Overbeck June 3, 2019 at 7:24 pm - Reply

    Is it hard to move from java to c++ ?

  31. Patrick Roth June 3, 2019 at 7:24 pm - Reply

    In the previous video you explained you can print out an one-dimensional array like this: 
    String[] texts = {"hello", "how", "are", "you?};
    for(String text: texts) {
             System.out.println(text);
    }

    Is there a similar way to do this "shortcut" with an multi-dimensional array?

  32. Fridabp June 3, 2019 at 7:24 pm - Reply

    I get [Ljava.lang.String;@6d4b2819 when i try to run it. How to fix it?

  33. John b June 3, 2019 at 7:24 pm - Reply

    I probably understood about 65% of what you have on your tut. But, I am new to this java stuff. Thanks for sharing dude!

    You have been thumbed up!

    Oink! Oink!

  34. Cave of Programming June 3, 2019 at 7:24 pm - Reply

    You need to type and run programs — Don't try to memorise, and don't stress over trying to understand intellectually. That would be like trying to learn the piano by reading a book about pianos instead of practising.

  35. J.D.M's June 3, 2019 at 7:24 pm - Reply

    i'm totally lost.

  36. Cave of Programming June 3, 2019 at 7:24 pm - Reply

    It affects a few little things here and there. You must always use "new" with non-primitive types, but never with primitive types. There are some other things like that.

  37. Sagiri June 3, 2019 at 7:24 pm - Reply

    Okay, so I understand the difference between primitive and nonprimitive data types.

    But, in practical terms – how does this affect how they are used?

  38. Wayne Marshall June 3, 2019 at 7:24 pm - Reply

    Thanks

Leave A Comment

*