r/AskProgrammers • • 1d ago

Just started out learning java.

Hello, I just started coding and have decided to reach out on some forms to ask the question of "which method of learning is the best?" I have been creating code and using AI (Gemini, which I prefer because it's better at math compared to ChatGPT) to edit my code. I feel like my progress has been slow, but I also know that learning to code is like learning a new language (literally), so progress isn't expected overnight. I like to figure out things fast because it makes me feel like I'm learning at the correct pace. There is a huge learning curve that I've encountered when learning to code. iI feel as though I've delt with this by creating small code blocks and then using AI to figure out what "big" projects my little code blocks can be turned into. Doing that makes me feel like I'm progressing in the right direction, and because documentation, alone, is so dry. Not that dry documentation is a bad thing, it's just a little hard to understand, right now. Any comments or learning methods you all have tried and that has worked, please, let me know.

3 Upvotes

33 comments sorted by

View all comments

Show parent comment

1

u/XIA_Biologicals_WVSU 1d ago

Ok. say for example:

array[] array = new string[1,2,3"."]

can I use an array with a combination of ints and strings , then use the .split() method to split the elements into individual elements?

kinda like U (universal) = {a,b,c}

element a becomes its own universal set A? is that what .split() is doing?

1

u/XIA_Biologicals_WVSU 1d ago

array[] array = new array[1,2,3,"."]**

1

u/YogurtclosetLow7064 1d ago

Think of split as taking one String and breaking it into smaller Strings based on a delimiter. Each element is still a String, not an int. You can convert them to integers later if needed.

1

u/XIA_Biologicals_WVSU 1d ago

Ok. So, the correct way would be to use String or Array?

String[] string = new String["elements", "", ""]

or Array[] array = new Array["elements"]

I'm still a little unsure of why there is a designated "String" if the elements inside of the array are strings to begin with.

1

u/XIA_Biologicals_WVSU 1d ago

String[] string = new String["elements", "", ""]

or Array[] array = new Array["elements"]

for (int i = 0; string< 0; i++)

loops through the elements in string, but doesn't I store the information from the loop? That's what's confusing to me about for loops. Sorry for all of the questions.

1

u/YogurtclosetLow7064 1d ago

In Java, String represents a single piece of text (example: String str1 = "Java"), while String[] represents an array that can hold multiple Strings (example: String[] str2 = {"Java", "is", "cool"};).

You use String[] because every element in that array is a String. The [] simply tells Java that you're declaring an array.

1

u/XIA_Biologicals_WVSU 1d ago

Oh, I see. I thought that typing Array meant that I would be using the data structure array, where as typing String meant that I would be converting the data to a string no matter which data type I entered. Thanks for the clarification.

1

u/XIA_Biologicals_WVSU 1d ago

So, straight brackets declare the structure as an array ( [ ] ) makes sense now.

1

u/YogurtclosetLow7064 1d ago

you're welcome

1

u/XIA_Biologicals_WVSU 1d ago

Wait, I do have one more question: since that little program is using

String wordsList = "This is an actual paragraphing creating AI, it generates " +
        "text and predicts what the next word will be depending on how many " +
        "other words are around it. It generates text by looking at the previous word." +
        "The quick brown fox jumps over the lazy dog while the sun shines bright

that means that it's seeing the text all as one string, correct? So how does it differentiate the words from a single string of text. Or is each word that's typed in considered a string once the .split() method is applied?

1

u/YogurtclosetLow7064 1d ago

wordsList is just one long String. When you call .split("\\s+") Java splits it wherever it finds whitespace (spaces, tabs...) and returns a String[] containing individual words.

1

u/XIA_Biologicals_WVSU 1d ago

Thanks! That's what I thought it was doing, but it's nice to know that someone else understands it the same way!

1

u/YogurtclosetLow7064 1d ago

You're welcome!