What is sub.string() ? In java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What is sub.string() ? In java

13th Dec 2019, 4:09 PM
Deena Dhayalan.S
Deena Dhayalan.S - avatar
19 Answers
+ 2
You are looking for something like this? String str= new String("quick brown fox jumps over the lazy dog"); System.out.println("Substring starting from index 15:"); System.out.println(str.substring(15)); System.out.println("Substring starting from index 15 and ending at 20:"); System.out.println(str.substring(15, 20));
13th Dec 2019, 4:32 PM
Coding Cat
Coding Cat - avatar
+ 2
String a = "Learning java is fun"; System.out.println(a.substring(1,8)); From index 1 to index 8-1 So it will print "earning" Edit: It will not print the character at the index 8.
13th Dec 2019, 5:11 PM
Avinesh
Avinesh - avatar
+ 1
Yes, that's what it should do. It's Java's Substring function. But if you know that, what's your question?
13th Dec 2019, 4:38 PM
Coding Cat
Coding Cat - avatar
13th Dec 2019, 5:40 PM
Avinesh
Avinesh - avatar
+ 1
13th Dec 2019, 5:45 PM
Avinesh
Avinesh - avatar
0
it returns part of string String str = "my string"; System.out.println( str.substring(0,6) ); //my str
13th Dec 2019, 4:33 PM
zemiak
0
Lol, zemiak you are not the TO ๐Ÿ˜‚
13th Dec 2019, 4:46 PM
Coding Cat
Coding Cat - avatar
0
@Thomas I want to know who it's work!?๐Ÿ˜… Can you explain
13th Dec 2019, 4:48 PM
Deena Dhayalan.S
Deena Dhayalan.S - avatar
0
zemiak bro I can't understand!! It is found by index!!
13th Dec 2019, 4:49 PM
Deena Dhayalan.S
Deena Dhayalan.S - avatar
0
Yes, it works by Index. Look at the example I have postet above. You will get a substring 1. from start index to end of String. Or: 2. From start index to end index
13th Dec 2019, 4:57 PM
Coding Cat
Coding Cat - avatar
0
Then what will be out for that!?
13th Dec 2019, 5:01 PM
Deena Dhayalan.S
Deena Dhayalan.S - avatar
0
Output for the exames above: Substring starting from index 15: jumps over the lazy dog Substring starting from index 15 and ending at 20: jump
13th Dec 2019, 5:05 PM
Coding Cat
Coding Cat - avatar
0
Ohh tq Thomas ๐Ÿ˜...
13th Dec 2019, 5:07 PM
Deena Dhayalan.S
Deena Dhayalan.S - avatar
0
String a= "abcd"; System.out.println(a.substring(2)); Output : cd Or : c only!!?
13th Dec 2019, 5:39 PM
Deena Dhayalan.S
Deena Dhayalan.S - avatar
0
Avinesh so if we didn't mention the end string index then it will show till the end!?
13th Dec 2019, 5:44 PM
Deena Dhayalan.S
Deena Dhayalan.S - avatar
0
Tq bro Avinesh ๐Ÿ˜...
13th Dec 2019, 5:46 PM
Deena Dhayalan.S
Deena Dhayalan.S - avatar
0
Or are you trying to convert a variable sub from another data type to a string datatype?
14th Dec 2019, 11:35 PM
Codebeast**
Codebeast** - avatar
0
Gduhvt479,;'%-
15th Dec 2019, 1:37 PM
Sooryajith
0
ะงะตะตะตะตะต
15th Dec 2019, 3:22 PM
ะฟั€ะพัั‚ะพ fire4ik
ะฟั€ะพัั‚ะพ fire4ik - avatar