-4

I have a string like this - "5,password,6099000,tree,city".

I want to extract only password from it. This means anything after first comma and before second comma.

How do I do this?

ruben
  • 1,745
  • 5
  • 25
  • 47
Maria890
  • 21
  • 1
  • 2

4 Answers4

3

The easiest solution might be to split the string on comma:

String input = "5,password,6099000,tree,city";
String[] parts = input.split(",");
String password = parts[1];
Tim Biegeleisen
  • 502,043
  • 27
  • 286
  • 360
0

Use the function Split(),

String example = "5,password,6099000,tree,city";    
String[] parts = example.split(",");
System.out.println(parts[1]);

Also look here: How to split a string in Java

MercyDude
  • 884
  • 10
  • 27
0

there you go

this will work

 String str="5,password,6099000,tree,city"
  String parts[]=str.split(",");
    String part1 = parts[0]; // 5
    String part2 = parts[1]; //Password
    
Community
  • 1
  • 1
Aqua 4
  • 771
  • 2
  • 9
  • 26
0
String string = "5,password,6099000,tree,city";
String subString = string.substring(2,10);

I assume you are a Java beginner, you may want to check

String Manipulation

Ege Kuzubasioglu
  • 5,991
  • 12
  • 49
  • 85